Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven maven-exec-plugin multiple execution configurations

Tags:

maven-2

maven

Is it possible to invoke a maven-exec-plugin (or any other plugin's) execution by its id from the command line?

Let's say my pom.xml file looks like this:

<project> [...]     <plugin>     <groupId>org.codehaus.mojo</groupId>     <artifactId>exec-maven-plugin</artifactId>     <executions>         <execution>             <id>foo</id>             <goals>                 <goal>exec</goal>             </goals>             <phase></phase>             <configuration>                 <executable>echo</executable>                 <arguments>                     <argument>foo</argument>                 </arguments>             </configuration>         </execution>         <execution>             <id>bar</id>             <goals>                 <goal>exec</goal>             </goals>             <phase></phase>             <configuration>                 <executable>echo</executable>                 <arguments>                     <argument>bar</argument>                 </arguments>                 </configuration>             </execution>         </executions>     </plugin> [...] </project> 

Now is it possible to call

mvn exec:exec

with some added magic to run execution "foo"?

For the curious there is an alternative solution using profiles available here: http://www.mail-archive.com/[email protected]/msg00151.html

like image 341
Maciej Biłas Avatar asked Feb 03 '10 14:02

Maciej Biłas


People also ask

What does mvn exec exec do?

Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process. exec:java - can be used to run a Java program in the same VM.

What is the difference between plugin and pluginManagement tags?

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

What is the correct syntax for executing a maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .

Are maven plugins executed in order?

Plugin executions are ordered according to their phases. See https://maven.apache.org/ref/current/maven-core/lifecycles.html for the order of phases. For example, here mavin-plugin-1 is executed before maven-plugin-2 because the process-resources phase is defined as taking place before the compile phase.


2 Answers

It is now possible, starting from Maven 3.3.1: see improvement MNG-5768 and Maven 3.3.1 release notes

You can call a specific execution configuration with this syntax:

mvn exec:exec@foo 
like image 78
slanglois Avatar answered Sep 28 '22 06:09

slanglois


No, it's not possible. Executions are for binding to the lifecycle (i.e. they are not designed to be invoked on the command line). So you'll have to use the profile trick described in the link that you provided.

like image 40
Pascal Thivent Avatar answered Sep 28 '22 07:09

Pascal Thivent