You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Julien Stern <ju...@cryptolog.com> on 2008/02/20 19:06:35 UTC

Extending Maven2 plugins

Hi list,

I just tried to "extend" a plugin, by creating a local plugin
with a Mojo that extends (in the Java sense) an other Mojo
from an existing plugin.

It overrides the execute method and calls several "super" methods
along with doing its own work.

However, when I try to execute the plugin, none of the "parameters"
seem to be set and I keep on getting NullPointerExceptions.

For instance, "project", as defined below in a super class in "null".

	/**
	 * POM.
	 * 
	 * @parameter expression="${project}"
	 * @readonly
	 * @required
	 */
	protected MavenProject project;
 
It that a bug? Is there a way to do want I'm trying to do?

Regards,

--
Julien

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Extending Maven2 plugins

Posted by Sahoo <Sa...@Sun.COM>.
See http://jira.codehaus.org/browse/MNG-3042 and 
http://jira.codehaus.org/browse/MPLUGIN-56. I hope they get fixed soon.

Thanks,
Sahoo

Rémy Sanlaville wrote:
> Hi Julien,
>
> I am not an expert but, what I understood, it is not possible to extend a
> mojo for the moment.
> Look at the archive of the mailing list maven-user and maven-dev. You will
> find some post related to this question.
>
> Rémy
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Extending Maven2 plugins

Posted by Rémy Sanlaville <re...@gmail.com>.
Hi Julien,

I am not an expert but, what I understood, it is not possible to extend a
mojo for the moment.
Look at the archive of the mailing list maven-user and maven-dev. You will
find some post related to this question.

Rémy

Re: Extending Maven2 plugins

Posted by Julien Stern <ju...@cryptolog.com>.
Hi Stuart,

I tried it and it worked like a charm.
Great plugin !
Thanks a lot.

--
Julien

PS: thank you Rémy and Sahoo too for your answers

On Thu, Feb 21, 2008 at 11:45:09AM +0800, Stuart McCulloch wrote:
> On 21/02/2008, Julien Stern <ju...@cryptolog.com> wrote:
> >
> > Hi list,
> >
> > I just tried to "extend" a plugin, by creating a local plugin
> > with a Mojo that extends (in the Java sense) an other Mojo
> > from an existing plugin.
> >
> > It overrides the execute method and calls several "super" methods
> > along with doing its own work.
> >
> > However, when I try to execute the plugin, none of the "parameters"
> > seem to be set and I keep on getting NullPointerExceptions.
> >
> > For instance, "project", as defined below in a super class in "null".
> >
> >         /**
> >          * POM.
> >          *
> >          * @parameter expression="${project}"
> >          * @readonly
> >          * @required
> >          */
> >         protected MavenProject project;
> >
> > It that a bug? Is there a way to do want I'm trying to do?
> 
> 
> Hi Julien,
> 
> when you build a maven plugin, the [plugin:descriptor] goal generates an XML
> file
> to target/classes/META-INF/maven/plugin.xml that tells the plexus container
> what
> fields need to be injected, and where to get them from (along with defaults,
> etc.)
> 
> unfortunately, the tool used to generate the plugin.xml works on javadoc
> comments
> which means that when you extend a mojo from another project, it doesn't see
> the
> source (and therefore the javadoc) and doesn't add the fields to the
> plugin.xml
> 
> this means when you come to use the extended mojo, a lot of the fields will
> be null.
> 
> I do have a tool (another maven plugin) that will help add inherited fields
> and goals
> to the plugin.xml, which is documented here (may upload it to repo1 if it's
> useful):
> 
> 
> http://www.ops4j.org/projects/pax/construct/maven-inherit-plugin/index.html
> 
> however, you do need to have the plugin being extended as a dependency in
> your
> new plugin project, and some people have said this is not necessarily a good
> thing
> 
> btw, if you have commit access to both codebases, another solution is to
> refactor
> the common code into a plexus component that can then be used in both
> plugins.
> 
> HTH
> 
> Regards,
> >
> >
> > --
> > Julien
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> 
> -- 
> Cheers, Stuart

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Extending Maven2 plugins

Posted by Stuart McCulloch <st...@jayway.net>.
On 21/02/2008, Julien Stern <ju...@cryptolog.com> wrote:
>
> Hi list,
>
> I just tried to "extend" a plugin, by creating a local plugin
> with a Mojo that extends (in the Java sense) an other Mojo
> from an existing plugin.
>
> It overrides the execute method and calls several "super" methods
> along with doing its own work.
>
> However, when I try to execute the plugin, none of the "parameters"
> seem to be set and I keep on getting NullPointerExceptions.
>
> For instance, "project", as defined below in a super class in "null".
>
>         /**
>          * POM.
>          *
>          * @parameter expression="${project}"
>          * @readonly
>          * @required
>          */
>         protected MavenProject project;
>
> It that a bug? Is there a way to do want I'm trying to do?


Hi Julien,

when you build a maven plugin, the [plugin:descriptor] goal generates an XML
file
to target/classes/META-INF/maven/plugin.xml that tells the plexus container
what
fields need to be injected, and where to get them from (along with defaults,
etc.)

unfortunately, the tool used to generate the plugin.xml works on javadoc
comments
which means that when you extend a mojo from another project, it doesn't see
the
source (and therefore the javadoc) and doesn't add the fields to the
plugin.xml

this means when you come to use the extended mojo, a lot of the fields will
be null.

I do have a tool (another maven plugin) that will help add inherited fields
and goals
to the plugin.xml, which is documented here (may upload it to repo1 if it's
useful):


http://www.ops4j.org/projects/pax/construct/maven-inherit-plugin/index.html

however, you do need to have the plugin being extended as a dependency in
your
new plugin project, and some people have said this is not necessarily a good
thing

btw, if you have commit access to both codebases, another solution is to
refactor
the common code into a plexus component that can then be used in both
plugins.

HTH

Regards,
>
>
> --
> Julien
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Cheers, Stuart