【发布时间】:2021-08-20 09:14:17
【问题描述】:
出于解释目的,假设我想:
- 复制项目工件 jar (maven-antrun-plugin)
- 复制依赖项(maven-dependency-plugin)
- 编译安装程序(maven-antrun-plugin)
不幸的是,两个 maven-antrun-plugin 执行是一起运行的。有关于重复插件声明的警告,它们在有效的 POM 中合并在一起。
编辑: 这个特定任务可以通过使用其他阶段或 install4j 插件来解决,但我感兴趣的是它是否通常可以执行,例如maven-antrun-plugin 在同一阶段以特定顺序多次(中间有其他插件)。
<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>
合并的有效 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>
【问题讨论】:
-
也许我弄错了,但为什么不使用 maven 插件? ej-technologies.com/resources/install4j/help/doc/cli/maven.html
-
@khmarbaise 是的,install4j 插件可用于此特定任务。但它更多地是作为一个例子来解释我的问题
-
让插件运行的唯一方法是将该插件绑定到不同的生命周期阶段...
标签: maven maven-3 maven-antrun-plugin