Maven 2.x Plugin Tools

Extending a Mojo Class and used in a new Mojo Project, parameter fields in the parent mojo are not set, this disables reuse of existing mojo project.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Java Plugins
  • Labels:
    None
  • Number of attachments :
    0

Description

I have an Existing maven-plugin-a and I want to extend its functionality and put it in maven-plugin-b, so what i did is I put the the maven-plugin-a as a dependecy in maven-plugin-b and extended the mojo class from A, the issue on this is that paramter fields from A is not set, when I used plugin-B, I think this disables reusing and extending of mojos

Issue Links

Activity

Hide
Jörg Hohwiller added a comment -

I have the same problem/need.

Show
Jörg Hohwiller added a comment - I have the same problem/need.
Hide
Marvin Froeder added a comment -

On the same boat...

Have the same need too.

Show
Marvin Froeder added a comment - On the same boat... Have the same need too.
Hide
Petar Tahchiev added a comment -

I have the same problem - I want to extend the surefire plugin and every time I run it, I get a null-pointer exception, because the instant variables are null. According to maven-inherit plugin I have to propagate the fields using reflection. Well, propagation in my case does not work, because the fields in the surefire plugin are all private , and I get a:

can not access a member of class org.apache.maven.plugin.surefire.SurefirePlugin with modifiers "private"

exception.

Any other suggestions?

Show
Petar Tahchiev added a comment - I have the same problem - I want to extend the surefire plugin and every time I run it, I get a null-pointer exception, because the instant variables are null. According to maven-inherit plugin I have to propagate the fields using reflection. Well, propagation in my case does not work, because the fields in the surefire plugin are all private , and I get a: can not access a member of class org.apache.maven.plugin.surefire.SurefirePlugin with modifiers "private" exception. Any other suggestions?
Hide
Stuart McCulloch added a comment -

FYI, you only need to propagate values using reflection if you override the field, ie. you declare a field in your mojo that "hides" a field of the same name in original mojo. You only usually need to do this if you need to change the default, or want access to the field - although in the latter case you could use reflection to read the field rather than override it. ( interestingly, if the overridden field is a @parameter then your new field will be injected instead of the original - but if it's an @component then it appears the original field is injected rather than the original )

Note that you can read and write private fields using reflection - you just need to use setAccessible(true) on the field to make it accessible, as shown in:

http://www.ops4j.org/projects/pax/construct/maven-pax-plugin/xref/org/ops4j/pax/construct/util/ReflectMojo.html

btw, in the maven-pax-plugin I extend a number of different mojos and override a couple of private fields, so I know this works in practice.

Show
Stuart McCulloch added a comment - FYI, you only need to propagate values using reflection if you override the field, ie. you declare a field in your mojo that "hides" a field of the same name in original mojo. You only usually need to do this if you need to change the default, or want access to the field - although in the latter case you could use reflection to read the field rather than override it. ( interestingly, if the overridden field is a @parameter then your new field will be injected instead of the original - but if it's an @component then it appears the original field is injected rather than the original ) Note that you can read and write private fields using reflection - you just need to use setAccessible(true) on the field to make it accessible, as shown in: http://www.ops4j.org/projects/pax/construct/maven-pax-plugin/xref/org/ops4j/pax/construct/util/ReflectMojo.html btw, in the maven-pax-plugin I extend a number of different mojos and override a couple of private fields, so I know this works in practice.
Hide
Brian Fox added a comment -

inheriting mojos across plugins is not currently supported. We should consider for 2.1

Show
Brian Fox added a comment - inheriting mojos across plugins is not currently supported. We should consider for 2.1
Hide
Andrew Lee Rubinger added a comment -

Would appreciate the implementation to use annotations with retention=RUNTIME.

S,
ALR

Show
Andrew Lee Rubinger added a comment - Would appreciate the implementation to use annotations with retention=RUNTIME. S, ALR
Hide
lisak added a comment -

+1 annotations
MPLUGIN-189
MNG-2521

Show
lisak added a comment - +1 annotations MPLUGIN-189 MNG-2521

People

Vote (12)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: