You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by animator <l....@gmail.com> on 2014/09/21 12:28:57 UTC

Problem while getting injected parameters from plugin configuration.

Hi,

I'm developing custom reporting  plugin for my own needs. I use Java 7,
Maven 3.1. I have a problem with getting injected parameters from plugin
configuration. In Mojo class I've field like:

    @Parameter
    private String srcDirClj;

and in different project that I want to execute on this plugin I have
following configuration:
       ...
    <reporting>
        <plugins>
            <plugin>
                <groupId>com.blah.bla</groupId>
                <artifactId>animator-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <srcDirClj>src/main/clojure</srcDirClj>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
       ...

And while invoking this mojo I always get null value for this configuration.
What is the problem with this? Is there any additional configuration that I
have to set?

When I declar property like that:
    @Parameter(property = "source.directory")
    private File srcDirClj;

and add properties configuration outside plugin declaration in POM:
    ...
   <properties>
        <source.directory>src/main/clojure</source.directory>
   </properties>
    ...   
it works, but I don't think that it is nice solution.

I have spent quite long time but I could't figure out why this approach
doesn't work. 
I read http://maven.apache.org/guides/mini/guide-configuring-plugins.html ,
http://people.apache.org/~ltheussl/maven-stage-site/guides/plugin/guide-java-plugin-development.html
and many other posts but cannot find explanation. 

Thanks for any help!



--
View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Igor Fedorenko <ig...@ifedorenko.com>.
You need to use org.apache.maven.plugins.annotations.Component
annotation inside maven plugins, I don't believe plexus @Requirement
works.

--
Regards,
Igor

On 2014-09-22, 18:34, animator wrote:
> The main problem from the topic finally I managed to resolve. The problem was
> wrong configuration in test-polyglot-project, the groupId of declared plugin
> in pom was wrong and when the goal was executed it was used plugin from
> local repository and any configuration from pom was omitted.. Anyway thanks
> for advices!
>
> Second problem with injecting plexus components still exists.. I added no
> arg constructor and @Requirement annotation but still I get the same
> exceptions.
>
> Thanks for answers.
>
>
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5806136.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by animator <l....@gmail.com>.
Thank You @Stuart McCulloch (and others that helped me in this topic)! Your
explanation is very valuable and resolved my problems :)

Regards,
animator.



--
View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5806319.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Stuart McCulloch <mc...@gmail.com>.
On 22 Sep 2014, at 23:34, animator <l....@gmail.com> wrote:

> The main problem from the topic finally I managed to resolve. The problem was
> wrong configuration in test-polyglot-project, the groupId of declared plugin
> in pom was wrong and when the goal was executed it was used plugin from
> local repository and any configuration from pom was omitted.. Anyway thanks
> for advices!
> 
> Second problem with injecting plexus components still exists.. I added no
> arg constructor and @Requirement annotation but still I get the same
> exceptions.

Hi,

I took a quick look at your project, to get Maven to see ClojureExecutorImpl as a Plexus component you need to generate some extra XML metadata for it (this is separate to the Maven plugin metadata generation):

            <plugin>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-component-metadata</artifactId>
                <version>1.5.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-metadata</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

This writes a file to "target/classes/META-INF/plexus/components.xml” which Plexus* will read to discover the components. Maven configures Plexus to only use index files, rather than full classpath scanning, so without this metadata the component won’t be visible. Note that if you only plan to target Maven 3.1.x and above then you can use the more modern JSR330 annotations as explained in http://maven.apache.org/maven-jsr330.html and http://wiki.eclipse.org/Sisu/PlexusMigration - but for maximum Maven compatibility its best to stick with Plexus annotations for now (at least wrt re-usable components, Maven mojos should use the mojo-specific annotations).

Secondly, ClojureExecutorImpl should inject the Plexus logger (org.codehaus.plexus.logging.Logger) because the Maven logger (org.apache.maven.plugin.logging.Log) is a special component only visible to mojos and is not available for Plexus components - underneath it logs to the same place, just gets exposed as a different API according to the injection context. The mojo specific injection is handled in a layer built on top of Plexus.

BTW if ClojureExecutorImpl is not expected to have injected setters/fields (apart from logging), or you plan to only create instances using new, then making it a Plexus component is overkill. Looking at other maven plugins they typically either have non-injected components that they assemble themselves, or they use simple Plexus components and pass any Maven-specific context (that’s not visible to the Plexus context) in as method parameters.

Anyway, with these two changes I was able to get the plugin working in the test project, so hopefully this explanation helps.

* actually the work is being done by Sisu’s Plexus adapter, which provides Plexus API+semantics on top of Guice

> Thanks for answers.
> 
> --
> View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5806136.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org


Re: Problem while getting injected parameters from plugin configuration.

Posted by animator <l....@gmail.com>.
The main problem from the topic finally I managed to resolve. The problem was
wrong configuration in test-polyglot-project, the groupId of declared plugin
in pom was wrong and when the goal was executed it was used plugin from
local repository and any configuration from pom was omitted.. Anyway thanks
for advices!

Second problem with injecting plexus components still exists.. I added no
arg constructor and @Requirement annotation but still I get the same
exceptions.

Thanks for answers.



--
View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5806136.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Stuart McCulloch <mc...@gmail.com>.
On 21 Sep 2014, at 22:54, animator <l....@gmail.com> wrote:

> Thanks for answers! 
> 
> I removed reporting section and unfortunately it doesn't work.. (*1)(btw.
> before that I added reporting api and declared InstrumentMojo extends
> AbstractMavenReport but this doesn't work too). 
> 
> I suppose may be there is problem with plexus, because when I added
> Component annotations that you suggested (*2) I got following error:

If you want ClojureExecutorImpl to be a Plexus @Component then you should provide a no-argument constructor, since Plexus semantics only support setter or field injection (using @Requirement to mark the method/field).

To access the Log inside your component, either add a @Requirment annotated setter/field or extend AbstractLogEnabled.

> /...
> [WARNING] Error injecting:
> com.gadawski.maven.plugins.cloverage.goals.InstrumentMojo
> com.google.inject.ProvisionException: Guice provision errors:
> 
> 1) No implementation for
> com.gadawski.maven.plugins.cloverage.ClojureExecutor was bound.
>  while locating com.gadawski.maven.plugins.cloverage.goals.InstrumentMojo
> .../
> 
> despite adding needed annotations. Do I need any special configuration for
> plexus or anything else?
> 
> *1
> https://github.com/lgadawski/test-polyglot-project/commit/ef847f98381adcb1127ab278b84962a201195d7a
> *2
> https://github.com/lgadawski/cloverage-maven-plugin/commit/0f99966fbb965be8c4d79845617e0a4ed748bc54
> 
> 
> 
> --
> View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5805996.html
> Sent from the Maven Developers mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
> 


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


Re: Problem while getting injected parameters from plugin configuration.

Posted by animator <l....@gmail.com>.
Thanks for answers! 

I removed reporting section and unfortunately it doesn't work.. (*1)(btw.
before that I added reporting api and declared InstrumentMojo extends
AbstractMavenReport but this doesn't work too). 

I suppose may be there is problem with plexus, because when I added
Component annotations that you suggested (*2) I got following error:

/...
[WARNING] Error injecting:
com.gadawski.maven.plugins.cloverage.goals.InstrumentMojo
com.google.inject.ProvisionException: Guice provision errors:

1) No implementation for
com.gadawski.maven.plugins.cloverage.ClojureExecutor was bound.
  while locating com.gadawski.maven.plugins.cloverage.goals.InstrumentMojo
.../

despite adding needed annotations. Do I need any special configuration for
plexus or anything else?

*1
https://github.com/lgadawski/test-polyglot-project/commit/ef847f98381adcb1127ab278b84962a201195d7a
*2
https://github.com/lgadawski/cloverage-maven-plugin/commit/0f99966fbb965be8c4d79845617e0a4ed748bc54



--
View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5805996.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Hervé BOUTEMY <he...@free.fr>.
no, there is absolutely nothing related to reporting plugins: reporting 
plugins are exactly like plugins

I didn't see test-polyglot-project, I just had a reaction when looking at the 
mojo source

when I look at  test-polyglot-project, I see another problem: why is it 
reclared in reporting section? The mojo is not a report mojo: a report mojo 
implements reporting-api
Then the configuration in reporting section is not used at all: that explains 
why it is not injected.
The configuration should be done in plugins or pluginManagement sections


But you're right, my answer about plexus component is completely not about the 
question; it's another topic :)

Regards,

Hervé

Le dimanche 21 septembre 2014 12:37:29 Igor Fedorenko a écrit :
> On 2014-09-21, 12:14, Hervé BOUTEMY wrote:
> > hte attribute "without property" seems to be expected to be a Plexus
> 
> > component, but you didn't declare it:
> Is this specific to reporting plugins? I believe regular plugins
> can have @Parameter's without properties and/or default values.
> 
> --
> Regards,
> Igor
> 
> > 1. in ClojureExecutorImpl, you should use Plexus @Component annotation
> > like
> > http://maven.apache.org/plugins-archives/maven-checkstyle-plugin-LATEST/xr
> > ef/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.html
> > 
> > 2. then inject the component into your plugin using plugin-tools
> > @Component
> > like
> > http://maven.apache.org/plugins-archives/maven-checkstyle-plugin-LATEST/x
> > ref/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.html#L439
> > 
> > notice these 2 @Component annotations are not the same ones: we should
> > have
> > named them differently...
> > 
> > the first one marks a class as a Plexus component:
> > http://plexus.codehaus.org/plexus-containers/plexus-component-annotations/
> > 
> > the second one injects a Plexus component into a Mojo:
> > http://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.
> > html
> > 
> > 
> > HTH
> > 
> > Regards,
> > 
> > Hervé
> > 
> > Le dimanche 21 septembre 2014 07:14:49 animator a écrit :
> >> Yes, of course,
> >> 
> >> plugin: https://github.com/lgadawski/cloverage-maven-plugin ,
> >> test project: https://github.com/lgadawski/test-polyglot-project
> >> 
> >> Mojo class:
> >> https://github.com/lgadawski/cloverage-maven-plugin/blob/master/src/main/
> >> jav a/com/gadawski/maven/plugins/cloverage/goals/InstrumentMojo.java I
> >> declared there 4 parameter, those declared with property attirubutes
> >> work fine, but those without, that reffers to configuration don't.
> >> 
> >> 
> >> 
> >> --
> >> View this message in context:
> >> http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameter
> >> s-> from-plugin-configuration-tp5805894p5805910.html Sent from the Maven
> >> Developers mailing list archive at Nabble.com.
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: dev-help@maven.apache.org
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> > For additional commands, e-mail: dev-help@maven.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org


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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Igor Fedorenko <ig...@ifedorenko.com>.
On 2014-09-21, 12:14, Hervé BOUTEMY wrote:
> hte attribute "without property" seems to be expected to be a Plexus
> component, but you didn't declare it:

Is this specific to reporting plugins? I believe regular plugins
can have @Parameter's without properties and/or default values.

--
Regards,
Igor


>
> 1. in ClojureExecutorImpl, you should use Plexus @Component annotation like
> http://maven.apache.org/plugins-archives/maven-checkstyle-plugin-LATEST/xref/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.html
>
> 2. then inject the component into your plugin using plugin-tools @Component
> like http://maven.apache.org/plugins-archives/maven-checkstyle-plugin-LATEST/xref/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.html#L439
>
> notice these 2 @Component annotations are not the same ones: we should have
> named them differently...
>
> the first one marks a class as a Plexus component:
> http://plexus.codehaus.org/plexus-containers/plexus-component-annotations/
>
> the second one injects a Plexus component into a Mojo:
> http://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html
>
>
> HTH
>
> Regards,
>
> Hervé
>
> Le dimanche 21 septembre 2014 07:14:49 animator a écrit :
>> Yes, of course,
>>
>> plugin: https://github.com/lgadawski/cloverage-maven-plugin ,
>> test project: https://github.com/lgadawski/test-polyglot-project
>>
>> Mojo class:
>> https://github.com/lgadawski/cloverage-maven-plugin/blob/master/src/main/jav
>> a/com/gadawski/maven/plugins/cloverage/goals/InstrumentMojo.java I declared
>> there 4 parameter, those declared with property attirubutes work fine, but
>> those without, that reffers to configuration don't.
>>
>>
>>
>> --
>> View this message in context:
>> http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-> from-plugin-configuration-tp5805894p5805910.html Sent from the Maven
>> Developers mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
>> For additional commands, e-mail: dev-help@maven.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Hervé BOUTEMY <he...@free.fr>.
hte attribute "without property" seems to be expected to be a Plexus 
component, but you didn't declare it:

1. in ClojureExecutorImpl, you should use Plexus @Component annotation like 
http://maven.apache.org/plugins-archives/maven-checkstyle-plugin-LATEST/xref/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.html

2. then inject the component into your plugin using plugin-tools @Component 
like http://maven.apache.org/plugins-archives/maven-checkstyle-plugin-LATEST/xref/org/apache/maven/plugin/checkstyle/AbstractCheckstyleReport.html#L439

notice these 2 @Component annotations are not the same ones: we should have 
named them differently...

the first one marks a class as a Plexus component:
http://plexus.codehaus.org/plexus-containers/plexus-component-annotations/

the second one injects a Plexus component into a Mojo:
http://maven.apache.org/plugin-tools/maven-plugin-tools-annotations/index.html


HTH

Regards,

Hervé

Le dimanche 21 septembre 2014 07:14:49 animator a écrit :
> Yes, of course,
> 
> plugin: https://github.com/lgadawski/cloverage-maven-plugin ,
> test project: https://github.com/lgadawski/test-polyglot-project
> 
> Mojo class:
> https://github.com/lgadawski/cloverage-maven-plugin/blob/master/src/main/jav
> a/com/gadawski/maven/plugins/cloverage/goals/InstrumentMojo.java I declared
> there 4 parameter, those declared with property attirubutes work fine, but
> those without, that reffers to configuration don't.
> 
> 
> 
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-> from-plugin-configuration-tp5805894p5805910.html Sent from the Maven
> Developers mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org


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


Re: Problem while getting injected parameters from plugin configuration.

Posted by animator <l....@gmail.com>.
Yes, of course, 

plugin: https://github.com/lgadawski/cloverage-maven-plugin , 
test project: https://github.com/lgadawski/test-polyglot-project

Mojo class:
https://github.com/lgadawski/cloverage-maven-plugin/blob/master/src/main/java/com/gadawski/maven/plugins/cloverage/goals/InstrumentMojo.java 
I declared there 4 parameter, those declared with property attirubutes work
fine, but those without, that reffers to configuration don't.



--
View this message in context: http://maven.40175.n5.nabble.com/Problem-while-getting-injected-parameters-from-plugin-configuration-tp5805894p5805910.html
Sent from the Maven Developers mailing list archive at Nabble.com.

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


Re: Problem while getting injected parameters from plugin configuration.

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi,

can you please show the full pom file of your plugin project ?

Is this project somewhere available on Github or so ? So we can take a 
look at it...


Kind regards
Karl-Heinz Marbaise
On 9/21/14 12:28 PM, animator wrote:
> Hi,
>
> I'm developing custom reporting  plugin for my own needs. I use Java 7,
> Maven 3.1. I have a problem with getting injected parameters from plugin
> configuration. In Mojo class I've field like:
>
>      @Parameter
>      private String srcDirClj;
>
> and in different project that I want to execute on this plugin I have
> following configuration:
>         ...
>      <reporting>
>          <plugins>
>              <plugin>
>                  <groupId>com.blah.bla</groupId>
>                  <artifactId>animator-maven-plugin</artifactId>
>                  <version>1.0-SNAPSHOT</version>
>                  <configuration>
>                      <srcDirClj>src/main/clojure</srcDirClj>
>                  </configuration>
>              </plugin>
>          </plugins>
>      </reporting>
>         ...
>
> And while invoking this mojo I always get null value for this configuration.
> What is the problem with this? Is there any additional configuration that I
> have to set?
>
> When I declar property like that:
>      @Parameter(property = "source.directory")
>      private File srcDirClj;
>
> and add properties configuration outside plugin declaration in POM:
>      ...
>     <properties>
>          <source.directory>src/main/clojure</source.directory>
>     </properties>
>      ...
> it works, but I don't think that it is nice solution.
>
> I have spent quite long time but I could't figure out why this approach
> doesn't work.
> I read http://maven.apache.org/guides/mini/guide-configuring-plugins.html ,
> http://people.apache.org/~ltheussl/maven-stage-site/guides/plugin/guide-java-plugin-development.html
> and many other posts but cannot find explanation.
>
> Thanks for any help!

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