You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mohammad Shamsi <m....@gmail.com> on 2013/04/28 10:28:25 UTC
How to add project classpath a to my Maven plugin
Hi All,
I'm developing a maven plugin and I need to access to the classpath of
project that is using my plugin, including main classes, test classes and
dependencies.
To me it seems a very common scenario, but I couldn't find any solution for
it in maven docs and other forums.
Thank you.
Mohammad Shamsi
Re: How to add project classpath a to my Maven plugin
Posted by Mohammad Shamsi <m....@gmail.com>.
Thanks Thomas, This is exactly what i needed.
On Sun, Apr 28, 2013 at 5:56 PM, Thomas Broyer <t....@gmail.com> wrote:
> On Sun, Apr 28, 2013 at 11:40 AM, Mohammad Shamsi <m....@gmail.com>
> wrote:
> > Sorry, my question was clear enough.
> >
> > I need to get the project classpath and add it to current classloader.
> > because the plugin needs to search and find some specific classes in the
> > project.
>
> The way I do it (inspired by many other plugins) is using
> ClassWorld/ClassRealm (a kind of URLClassLoader), but URLClassLoader
> will do just as well if you don't need anything fancy:
> Only direct dependencies:
>
> https://github.com/tbroyer/gwt-maven-plugin/blob/54fe4621d1ee5127b14030f6e1462de44bace901/src/main/java/net/ltgt/gwt/maven/GenerateModuleMojo.java#L218
> Including transitive dependencies (and sources):
>
> https://github.com/tbroyer/gwt-maven-plugin/blob/54fe4621d1ee5127b14030f6e1462de44bace901/src/main/java/net/ltgt/gwt/maven/CompileMojo.java#L295
>
>
> --
> Thomas Broyer
> /tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
--
Sincerely Yours
Mohammad H. Shamsi
Re: How to add project classpath a to my Maven plugin
Posted by Thomas Broyer <t....@gmail.com>.
On Sun, Apr 28, 2013 at 11:40 AM, Mohammad Shamsi <m....@gmail.com> wrote:
> Sorry, my question was clear enough.
>
> I need to get the project classpath and add it to current classloader.
> because the plugin needs to search and find some specific classes in the
> project.
The way I do it (inspired by many other plugins) is using
ClassWorld/ClassRealm (a kind of URLClassLoader), but URLClassLoader
will do just as well if you don't need anything fancy:
Only direct dependencies:
https://github.com/tbroyer/gwt-maven-plugin/blob/54fe4621d1ee5127b14030f6e1462de44bace901/src/main/java/net/ltgt/gwt/maven/GenerateModuleMojo.java#L218
Including transitive dependencies (and sources):
https://github.com/tbroyer/gwt-maven-plugin/blob/54fe4621d1ee5127b14030f6e1462de44bace901/src/main/java/net/ltgt/gwt/maven/CompileMojo.java#L295
--
Thomas Broyer
/tɔ.ma.bʁwa.je/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: How to add project classpath a to my Maven plugin
Posted by Mohammad Shamsi <m....@gmail.com>.
Sorry, my question was clear enough.
I need to get the project classpath and add it to current classloader.
because the plugin needs to search and find some specific classes in the
project.
On Sun, Apr 28, 2013 at 5:11 PM, Mohammad Shamsi <m....@gmail.com>wrote:
> How can then add them to plugin class path?
> On Apr 28, 2013 5:06 PM, "Thomas Broyer" <t....@gmail.com> wrote:
>
>> All you need is a reference to the MavenProject:
>>
>> @Parameter(defaultValue = "${project}", required = true, readonly =
>> true)
>> private MavenProject project;
>>
>> then you can use getClasspathElements(), getDependencyArtifacts(), etc.
>>
>> Of course you can also have those parts injected directly, for example:
>>
>> @Parameter(defaultValue = "${project.dependencyArtifacts}",
>> required = true, readonly = true)
>> private Set<Artifact> dependencyArtifacts;
>>
>>
>> On Sun, Apr 28, 2013 at 10:28 AM, Mohammad Shamsi <m....@gmail.com>
>> wrote:
>> > Hi All,
>> >
>> > I'm developing a maven plugin and I need to access to the classpath of
>> > project that is using my plugin, including main classes, test classes
>> and
>> > dependencies.
>> >
>> > To me it seems a very common scenario, but I couldn't find any solution
>> for
>> > it in maven docs and other forums.
>> >
>> > Thank you.
>> > Mohammad Shamsi
>>
>>
>>
>> --
>> Thomas Broyer
>> /tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
--
Sincerely Yours
Mohammad H. Shamsi
Re: How to add project classpath a to my Maven plugin
Posted by Mohammad Shamsi <m....@gmail.com>.
How can then add them to plugin class path?
On Apr 28, 2013 5:06 PM, "Thomas Broyer" <t....@gmail.com> wrote:
> All you need is a reference to the MavenProject:
>
> @Parameter(defaultValue = "${project}", required = true, readonly =
> true)
> private MavenProject project;
>
> then you can use getClasspathElements(), getDependencyArtifacts(), etc.
>
> Of course you can also have those parts injected directly, for example:
>
> @Parameter(defaultValue = "${project.dependencyArtifacts}",
> required = true, readonly = true)
> private Set<Artifact> dependencyArtifacts;
>
>
> On Sun, Apr 28, 2013 at 10:28 AM, Mohammad Shamsi <m....@gmail.com>
> wrote:
> > Hi All,
> >
> > I'm developing a maven plugin and I need to access to the classpath of
> > project that is using my plugin, including main classes, test classes and
> > dependencies.
> >
> > To me it seems a very common scenario, but I couldn't find any solution
> for
> > it in maven docs and other forums.
> >
> > Thank you.
> > Mohammad Shamsi
>
>
>
> --
> Thomas Broyer
> /tɔ.ma.bʁwa.je/ <http://xn--nna.ma.xn--bwa-xxb.je/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: How to add project classpath a to my Maven plugin
Posted by Thomas Broyer <t....@gmail.com>.
All you need is a reference to the MavenProject:
@Parameter(defaultValue = "${project}", required = true, readonly = true)
private MavenProject project;
then you can use getClasspathElements(), getDependencyArtifacts(), etc.
Of course you can also have those parts injected directly, for example:
@Parameter(defaultValue = "${project.dependencyArtifacts}",
required = true, readonly = true)
private Set<Artifact> dependencyArtifacts;
On Sun, Apr 28, 2013 at 10:28 AM, Mohammad Shamsi <m....@gmail.com> wrote:
> Hi All,
>
> I'm developing a maven plugin and I need to access to the classpath of
> project that is using my plugin, including main classes, test classes and
> dependencies.
>
> To me it seems a very common scenario, but I couldn't find any solution for
> it in maven docs and other forums.
>
> Thank you.
> Mohammad Shamsi
--
Thomas Broyer
/tɔ.ma.bʁwa.je/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org