For explanation purposes, assume I would like to:
- copy project artifact jar (maven-antrun-plugin)
- copy dependencies (maven-dependency-plugin)
- compile installer (maven-antrun-plugin)
Unfortunately both maven-antrun-plugin executions are run together. There is a warning about duplicate plugin declaration, and they are merged together in the effective POM.
Edit: This specific task could be solved by using other phases or the install4j plugin, but I am interested whether it is generally possible to execute e.g. maven-antrun-plugin multiple times during the same phase in a specific order (with other plugins in between).
<build>
<plugins>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- copy project jar -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-project-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy file="target/${project.artifactId}-${project.version}.jar"
tofile="target/installer/bin/${project.artifactId}.jar" />
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- copy dependencies -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/installer/bin</outputDirectory>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- compile installer -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~ -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>compile-installer</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="${install4j.home}/bin/install4jc.exe">
<arg value="installer.install4j" />
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Merged effective POM:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>copy-project-artifact</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy file="target/test-1.0.0.jar" tofile="target/installer/bin/test.jar" />
</target>
</configuration>
</execution>
<execution>
<id>compile-installer</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="C:\Program Files\install4j8/bin/install4jc.exe">
<arg value="installer.install4j" />
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
First of all, you need to put all executions into the same plugin definition.
Secondly, I doubt that this is possible, but usually you can split things up by using more phases. E.g. you could use
prepare-packagefor the first execution of the antrun plugin.