gpt4 book ai didi

java - 指定 Maven 插件执行的运行顺序

转载 作者:行者123 更新时间:2023-12-02 11:21:24 24 4
gpt4 key购买 nike

我正在使用copy-rename-maven-plugin期间package阶段首先复制jar我刚刚生成到另一个目录,然后使用 launch4j-maven-plugin我正在生成exe包裹 jar 的 s然后我需要重命名 exe 之一s (到 scr ),所以,我正在使用 copy-rename-maven-plugin再次。

问题是所有 copy-rename-maven-pluginlaunch4j-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>

执行需要运行的顺序是这样的:

  1. copy-jar-for-exe
  2. wrap-screensaver-as-exe
  3. rename-screensaver-to-scr

任何其他顺序都不起作用,但我认为是因为 copy-jar-for-exerenamer-screensaver-to-scr是来自同一个插件的执行,Maven 像这样运行它:

  1. copy-jar-for-exe
  2. rename-screensaver-to-scr
  3. wrap-screensaver-as-exe

所以,它失败了。

最佳答案

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

基本思想是,同一阶段执行的插件按照pom中出现的顺序执行。如果将单个执行绑定(bind)到另一个(较早的)阶段,则应在其之前执行。

我还没有测试过这个,但我认为它应该有效

<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>

关于java - 指定 Maven 插件执行的运行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49895450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com