Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I run a specific goal with a particular configuration in a Maven plugin when I have several configurations for that goal

See plugin config from pom.xml below.

I can do:

mvn myplugin:myGoal

Which runs myGoal (both executions I suppose) but I want to be able to choose either the first or the second executions independently.

I know I can add an id to the execution element, but how do I refer to that id on the command line. I'd like to get to something which does what this imagined command does:

mvn myplugin:myGoal --executionId=1

Is this possible, or am I going about this the wrong way?

        <plugin>             <groupId>org.myplugin</groupId>             <artifactId>myplugin-maven-plugin</artifactId>             <version>1.1.1</version>             <executions>                 <execution>                     <id>process-cats</id>                     <goals>                         <goal>myGoal</goal>                     </goals>                     <configuration>                         <myParam>cats</myParam>                     </configuration>                 </execution>                 <execution>                     <id>process-dogs</id>                     <goals>                         <goal>myGoal</goal>                     </goals>                     <configuration>                         <myParam>dogs</myParam>                     </configuration>                 </execution>             </executions>         </plugin> 
like image 980
lukewm Avatar asked Aug 10 '10 11:08

lukewm


People also ask

What are Maven plugins goals?

A Maven plugin is a group of goals; however, these goals aren't necessarily all bound to the same phase. As we can see, the Failsafe plugin has two main goals configured here: integration-test: run integration tests. verify: verify all integration tests passed.

Does Maven use configuration over convention?

Maven uses Convention over Configuration, which means developers are not required to create build process themselves. Developers do not have to mention each and every configuration detail. Maven provides sensible default behavior for projects. When a Maven project is created, Maven creates default project structure.

How do I run a Maven goal in eclipse?

How to Run Web Application. Create a run configuration by click "Run → Run Configurations", select Maven Build and click "New launch configuration", type Name "OpenMRS", select working directory to be the root of webapp project, type goal "jetty:run" and save. Now you select "OpenMRS" and run or debug it.


2 Answers

Execution of multiple goals from the CLI is now supported in Maven 3.3.1+

mvn exec:java@first-cli mvn exec:java@second-cli 

Where first-cli/second-cli are the execution ids.

https://blog.soebes.de/blog/2015/03/17/apache-maven-3-dot-3-1-features/

For your example the commands would be

mvn myplugin:mygoal@process-cats mvn myplugin:mygoal@process-dogs 
like image 167
mdi Avatar answered Sep 30 '22 10:09

mdi


I can do mvn myplugin:myGoalWhich runs myGoal (both executions I suppose)

None of them (assuming they had unique id). Executions are bound to a phase, you need to run the given phase to trigger them.

I know I can add an id to the execution element, but how do I refer to that id on the command line.

Not supported. What is possible for plugins invoked on the CLI is to define a non global configuration in the POM using the special default-cli executionId, like this:

<plugin>   <artifactId>maven-assembly-plugin</artifactId>   <executions>     <execution>       <id>default-cli</id>       <configuration>         <descriptorRefs>           <descriptorRef>jar-with-dependencies</descriptorRef>           <descriptorRef>project</descriptorRef>         </descriptorRefs>       </configuration>     </execution>   </executions> </plugin> 

Is this possible, or am I going about this the wrong way?

No, not possible. Either pass the parameters on the command line or use profiles (with or without the above default execution).

References

  • Default Plugin Execution IDs
  • http://jira.codehaus.org/browse/MNG-3203
  • http://jira.codehaus.org/browse/MNG-3401
like image 41
Pascal Thivent Avatar answered Sep 30 '22 08:09

Pascal Thivent