11

I'm analyzing a Maven plugin that I can configure inside the configuration section of plugin:

<plugin>
     ...
     <executions>...</executions>
     <configuration>
         <!-- items placed here are visible to the MOJO -->
     </configuration>
</plugin>

The plugin completely ignores any configuration items for an execution, though:

<plugin>
     ...
     <executions>
         <execution>
             <id>execution1</id>
             <phase>test</phase>
             <goals><goal>test</goal></goals>
             <configuration>
                <!-- items placed here are ignored -->
             </configuration>
         </execution>
     </executions>
</plugin>

I run Maven with mvn test. I'm sure that the execution takes place, as Maven prints its id correctly, but the plugin is not configured -- prints warnings about incorrect settings that are not present when the <configuration> section is moved outside of <executions>.

The question: is it the way the plugin is implemented, that it accepts only "top level" configuration? I've studied its source code and it seemed to me that it's Maven that invokes setters on a MOJO class and it's transparent to the plugin which section the options came from.

The MOJO is annotated with:

* @component
* @goal test
* @phase test
* @execute phase="jasmine-process-test-resources"
MaDa
  • 10,511
  • 9
  • 46
  • 84
  • You are right about the setters. Plexus is the DI framework. [Some more info on that.](http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-mojo-params.html) but note that thre is now a java annotations method for doing the injection. – Lee Meador Jan 28 '13 at 22:53
  • 1
    The executions's configuration only applies to the lifecycle bound execution. are you sure that is the execution you are invoking – Stephen Connolly Jan 29 '13 at 11:26
  • @StephenConnolly I guess... I've added MOJO configuration to my answer. – MaDa Jan 29 '13 at 14:03
  • @MaDa that makes no difference... (other than the phase is complete poppy-cock) we'd need to see your `` in the `` and ensure that you are specifying a phase on the CLI that is after the phase you have bound to – Stephen Connolly Jan 29 '13 at 14:33

2 Answers2

4

The plugin in question is forking a custom lifecycle.

The forked custom lifecycle will have the execution with the specified id (execution1) removed (as it is a forked lifecycle)

Thus any of the plugin's goals that are performed by the forked lifecycle will be missing their configuration. The main mojo itself should be getting the configuration, but what is going wrong is the forked lifecycle executions.

I am guessing which plugin it is, if my guess is right, this is the custom lifecycle and the warnings you are seeing are coming from e.g. other mojos with text like

JavaScript source folder was expected but was not found. Set configuration property
`jsSrcDir` to the directory containing your JavaScript sources. Skipping 
jasmine:resources processing.

With a situation like this you will need to either put the <configuration> section in the outer block or configure the executions for the lifecycle.

Configuring the executions for the lifecycle will require adding executions with ids that are of the magic format. I am not 100% certain, but in your case you would be defining an additional execution with an ids of either default-resources or jasmine-lifecycle-resources in order to ensure that the configuration takes.

The less verbose way is just to put the configuration in the outer section and be done with it.

MaDa
  • 10,511
  • 9
  • 46
  • 84
Stephen Connolly
  • 13,872
  • 6
  • 41
  • 63
  • 2
    Thanks. I still don't fully grasp the concept of a forked lifecycle, but you nudged me in the right direction. Putting the configuration in the outer section was not an option, I needed multiple executions with different set of parameters. – MaDa Jan 30 '13 at 09:53
  • @Mada what did you end up doing ? I have the same problem. I dont grasp the concept of forked lifecycle myself. I did not understand the bit about using 'magic ids' – arunkjn Apr 06 '17 at 13:18
  • 1
    This question was triggered by a Maven plugin for Jasmine (a JavaScript library). Soon after I had asked this, we decided to drop trying manage a JS application with Java and go for 100% JavaScript approach. – MaDa Apr 12 '17 at 13:16
0

I had this issue with the base maven-install-plugin:2.5.2 using the maven:3.6.3-jdk-8 docker image.

Thanks to the accepted answer for putting me on the right track.

I don't fully understand this note in the documentation (at the end of the section), but it seems that you can give the phase goal an execution id forcing it to use your configuration:

Note: Configurations inside the element used to differ from those that are outside in that they could not be used from a direct command line invocation because they were only applied when the lifecycle phase they were bound to was invoked. So you had to move a configuration section outside of the executions section to apply it globally to all invocations of the plugin. Since Maven 3.3.1 this is not the case anymore as you can specify on the command line the execution id for direct plugin goal invocation. Hence if you want to run the above plugin and it's specific execution1's configuration from the command-line, you can execute:

mvn myqyeryplugin:queryMojo@execution1

My final working docker command:

docker run -it --rm --name parser -v "$(shell pwd)":/usr/src/parser -w /usr/src/parser maven:3.6.3-jdk-8 mvn -X install:install-file@install-my-jar-file

Where install-my-jar-file is my executions id <execution><id>install-my-jar-file</id>...

Chris Gregory
  • 99
  • 1
  • 5