指定Maven插件执行的顺序

时间:2018-04-18 09:01:05

标签: java maven

我在copy-rename-maven-plugin阶段使用package首先将我刚刚生成的jar复制到另一个目录,然后使用launch4j-maven-plugin我正在生成{ {1}}包裹exe然后我需要重命名其中一个jar s(到exe),因此,我再次使用scr

问题是所有copy-rename-maven-plugin次执行都在copy-rename-maven-plugin之前一起运行,因此,第二次执行失败。

如何定义执行顺序?我很高兴创造更多阶段,如果这是必要的,但创建一个Maven插件似乎有点矫枉过正。

我的launch4j-maven-plugin内容的简化示例如下所示:

pom.xml

执行需要执行的顺序是:

  1. <?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>
  2. copy-jar-for-exe
  3. wrap-screensaver-as-exe
  4. 任何其他顺序都不起作用,但是因为我认为rename-screensaver-to-scrcopy-jar-for-exe是来自同一个插件的执行,Maven运行它是这样的:

    1. renamer-screensaver-to-scr
    2. copy-jar-for-exe
    3. rename-screensaver-to-scr
    4. 所以,它失败了。

1 个答案:

答案 0 :(得分:1)

您可以在准备包阶段运行copy-jar-for-exe。我相信你可以在同一个插件配置中定义两个执行,但是在launch4j插件之后声明插件。

基本思想是,在同一阶段执行的插件按照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>