maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stuart McCulloch" <stuart.mccull...@jayway.net>
Subject Re: Extending Maven2 plugins
Date Thu, 21 Feb 2008 03:45:09 GMT
On 21/02/2008, Julien Stern <julien.stern@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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message