Java 指定Maven插件的顺序';执行死刑
我在Java 指定Maven插件的顺序';执行死刑,java,maven,Java,Maven,我在包阶段使用copy rename maven plugin首先将我刚刚生成的jar复制到另一个目录,然后使用launch4j maven plugin生成包装jar的exes,然后我需要重命名其中一个exes(到scr),因此,我再次使用copy-rename-maven-plugin 问题在于,在启动4jmaven-plugin之前,所有复制重命名maven-plugin执行都一起运行,因此,第二次执行失败 如何定义执行顺序?如果有必要的话,我很乐意创建更多的阶段,但是创建一个Maven插
包
阶段使用copy rename maven plugin
首先将我刚刚生成的jar
复制到另一个目录,然后使用launch4j maven plugin
生成包装jar
的exe
s,然后我需要重命名其中一个exe
s(到scr
),因此,我再次使用copy-rename-maven-plugin
问题在于,在启动4jmaven-plugin
之前,所有复制重命名maven-plugin
执行都一起运行,因此,第二次执行失败
如何定义执行顺序?如果有必要的话,我很乐意创建更多的阶段,但是创建一个Maven插件似乎有点过分了
我的pom.xml
的简化示例如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.projecx</groupId>
<artifactId>projecx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the just-built projecx jar to targte/win32/jars -->
<id>copy-jar-for-exe</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <!-- Make the exes -->
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the screensaver from the exe to the proper scr -->
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
技术项目
项目
1.0.0-SNAPSHOT
org.apache.maven.plugins
maven编译器插件
3.7.0
1.8
1.8
com.coderplus.maven.plugins
复制重命名maven插件
1.0.1
为exe复制jar
包裹
复制
${project.build.directory}/${project.build.finalName}.jar
${project.build.directory}/win32/jars/${project.build.finalName}.jar
com.akatist.maven.plugins.launch4j
启动4J maven插件
1.7.21
将屏幕保护程序包装为exe
包裹
发射4J
桂
${project.build.directory}\win32\${screensaverExe}.exe
jars\${project.build.finalName}.jar
com.coderplus.maven.plugins
复制重命名maven插件
1.0.1
将屏幕保护程序重命名为scr
包裹
改名
${project.build.directory}/win32/${screensaverExe}.exe
${project.build.directory}/win32/${screensaverExe}.scr
执行需要按以下顺序运行:
复制jar for exe
将屏幕保护程序包装为exe
将屏幕保护程序重命名为scr
copyjarforexe
和renamer screensaver to scr
都是从同一个插件执行的,所以Maven会这样运行它:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>tech.projecx</groupId>
<artifactId>projecx</artifactId>
<version>1.0.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the just-built projecx jar to targte/win32/jars -->
<id>copy-jar-for-exe</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin> <!-- Make the exes -->
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution> <!-- Copy the screensaver from the exe to the proper scr -->
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
复制jar for exe
将屏幕保护程序重命名为scr
将屏幕保护程序包装为exe
因此,它失败了。您可以在准备包阶段运行exe的
复制jar
。我相信您可以在相同的插件配置中定义两个执行,但在启动4j插件后声明插件
基本思想是,在同一阶段执行的插件按照pom中的出现顺序执行。如果您将单个执行绑定到另一个(早期)阶段,那么它应该在执行之前执行
我还没有测试过这个,但我认为它应该可以工作
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.7.21</version>
<executions>
<execution> <!-- Make the screensaver exe -->
<id>wrap-screensaver-as-exe</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<outfile>${project.build.directory}\win32\${screensaverExe}.exe</outfile>
<jar>jars\${project.build.finalName}.jar</jar>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>copy-jar-for-exe</id>
<phase>prepare-package</phase> <!-- run this execution before package phase -->
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/${project.build.finalName}.jar</sourceFile>
<destinationFile>${project.build.directory}/win32/jars/${project.build.finalName}.jar
</destinationFile>
</configuration>
</execution>
<execution>
<id>rename-screensaver-to-scr</id>
<phase>package</phase>
<goals>
<goal>rename</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/win32/${screensaverExe}.exe</sourceFile>
<destinationFile>${project.build.directory}/win32/${screensaverExe}.scr</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
com.akatist.maven.plugins.launch4j
启动4J maven插件
1.7.21
将屏幕保护程序包装为exe
包裹
发射4J
桂
${project.build.directory}\win32\${screensaverExe}.exe
jars\${project.build.finalName}.jar
com.coderplus.maven.plugins
复制重命名maven插件
1.0.1
为exe复制jar
准备包装
复制
${project.build.directory}/${project.build.finalName}.jar
${project.build.directory}/win32/jars/${project.build.finalName}.jar
将屏幕保护程序重命名为scr
包裹
改名
${project.build.directory}/win32/${screensaverExe}.exe
${project.build.directory}/win32/${screensaverExe}.scr
您是否尝试过在测试阶段之前或之后将执行绑定到不同的阶段?@GeraldMücke:没有,因为我看不到任何合适的阶段可以这样做。Maven内置阶段集中只有一个阶段适合所有这些任务,那就是包
。我不希望任何打包发生在运行测试phase.hm的CI上,我可能仍然没有得到您想要实现的内容以及如何实现,也许这将有助于了解您到目前为止在pom.xml中所做的工作以及您打算在概念层面上实现的内容(一步一步),你能把这个问题补充一下吗?@GeraldMücke当然,请稍等。@GeraldMücke:好了,现在有意义了吗?