Execute multiple goals with parameters in maven
You want to execute multiple commands, so you want to have multiple executions of the plugin:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<!-- First execution executing jmeter-maven-plugin -->
<execution>
<id>runcommand1</id>
<goals>
<goal>exec</goal>
</goals>
<phase> <!-- you need to write a phase here --> </phase>
<configuration>
<arguments>
<argument>com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests -Dmyhost=hix.qa.com -Dmyport=80 -Dmyprotocol=http -Dmythreads=5 -Dmyloopcount=20 -Dmyrampup=1 -Dmytest=ScreenerAPI.jmx</argument>
</arguments>
</configuration>
</execution>
<!-- Second execution executing jmeter-graph-maven-plugin -->
<execution>
<id>runcommand2</id>
<goals>
<goal>exec</goal>
</goals>
<phase> <!-- you need to write a phase here --> </phase>
<configuration>
<arguments>
<argument>de.codecentric:jmeter-graph-maven-plugin:0.1.0:create-graph@create-graphs</argument>
</arguments>
</configuration>
</execution>
</executions>
<configuration>
<executable>mvn</executable>
</configuration>
</plugin>
This configuration does multiple things:
- It configures 2 executions for the 2 commands you want to invoke. They are both configured with the correct
<argument>
attribute. - It factors out the common configuration of those two inside the global configuration element. In this case, this is simply the executable.
There's an important factor though: those executions need to be bound to a phase if you want to execute both of them in a single build. As as example, if you bind them to verify
then invoking mvn verify
will invoke the two executions.
Related videos on Youtube
mo0206
Updated on June 04, 2022Comments
-
mo0206 almost 2 years
I am trying to execute multiple goals in maven
I have my Pom.xml like
<plugins> <plugin> <groupId>com.lazerycode.jmeter</groupId> <artifactId>jmeter-maven-plugin</artifactId> <version>1.4.1</version> <executions> <execution> <id>jmeter-tests</id> <phase>verify</phase> <goals> <goal>jmeter</goal> </goals> <configuration> <testFilesIncluded> <jMeterTestFile>${mytest}</jMeterTestFile> </testFilesIncluded> <propertiesUser> <hostName>${myhost}</hostName> <port>${myport}</port> <protocol>${myprotocol}</protocol> </propertiesUser> </configuration> </execution> </executions> </plugin> <plugin> <groupId>de.codecentric</groupId> <artifactId>jmeter-graph-maven-plugin</artifactId> <version>0.1.0</version> <executions> <execution> <id>create-graphs</id> <goals> <goal>create-graph</goal> </goals> <phase>verify</phase> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.4.0</version> <executions> <execution> <id>runcommand</id> <goals> <goal>exec</goal> </goals> </execution> </executions> <configuration> <executable>mvn</executable> <arguments> <argument>**com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests -Dmyhost=hix.qa.com -Dmyport=80 -Dmyprotocol=http -Dmythreads=5 -Dmyloopcount=20 -Dmyrampup=1 -Dmytest=ScreenerAPI.jmx**</argument> <argument>de.codecentric:jmeter-graph-maven-plugin:0.1.0:create-graph@create-graphs</argument> </arguments> </configuration> </plugin> </plugins>
I have two arguments mentioned in the org.codehaus plugin.
running the below command with argument1 disabled works fine.
mvn org.codehaus.mojo:exec-maven-plugin:1.4.0:exec@runcommand
But when I run the command with both are arguments enabled gives me an error
failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests -Dmyhost=hix.qa.com -Dmyport=80 -Dmyprotocol=http -Dmythreads=5 -Dmyloopcount=20 -Dmyrampup=1 -Dmytest=ScreenerAPI.jmx
running goal1 and goal2 indivudally with parameters from cmd line works fine.
mvn de.codecentric:jmeter-graph-maven-plugin:0.1.0:create-graph@create-graphs mvn com.lazerycode.jmeter:jmeter-maven-plugin:1.4.1:jmeter@jmeter-tests "-Dmyhost=hix.qa.com" "-Dmyport=80" "-Dmyprotocol=http" "-Dmythreads=5" "-Dmyloopcount=20" "-Dmyrampup=1" "-Dmytest=ScreenerAPI.jmx"
How to pass parameters to one goal from command line while running multiple goals?
-
Ardesco over 8 yearsYou are using very old versions of the meter-maven-plugin and the meter-graph-maven-plugin. I would suggest updating to the latest versions which are much more reliable.
-
-
mo0206 over 8 yearsI have many plugins in a POM.xml which are bound to verify phase.. So i would like to bind the executions to execution id rather than binding to verify. Since at different points I need to run different plugins. Using mvn verify runs all the plugins with verify phase right ?
-
Tunaki over 8 years@MonicaThaneer That's correct. Well you need to bind it to the phase you want (
verify
was just an example). But you need to split it into 2 executions, so 2 differents ids. -
mo0206 over 8 yearsapologies I am a newbie to maven! how would I use two different execution ids in one command?
-
Tunaki over 8 years@MonicaThaneer No that's the thing, you can't. I fear you are going the wrong way because that's not something you should make a habit of doing. The "normal" way is to bind plugin executions to phases and invoke Maven by passing in phases (like
mvn install
). In the end, you want Maven to package an artifact and you will invokemvn package
to get it. This, in turn, should invoke all the necessary plugins to make that packaging happen. Read about the Maven lifecycle.