在 maven 并行构建的情况下,最后执行 maven ant-运行 插件
Execute maven ant-run plugin in the end in case of maven parallel builds
我有一个 Maven 多模块项目。简化的 pom.xml
(在 full-build
下)如下所示:-
<?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>
<packaging>pom</packaging>
<groupId>com.eros</groupId>
<artifactId>full-build</artifactId>
<version>0.001-SNAPSHOT</version>
<name>full-build</name>
<profiles>
<profile>
<id>build-only</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>../../main</module>
</modules>
</profile>
<profile>
<id>copy-only</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<!-- collector -->
<copy file="../collector-framework/collector/target/collector-${project.version}.jar"
tofile="./target/collector/collector-${project.version}.jar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
main
中的简化 pom.xml
如下所示:-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.eros</groupId>
<artifactId>main</artifactId>
<version>0.001-SNAPSHOT</version>
<packaging>pom</packaging>
<name>main</name>
<modules>
<module>collector-framework</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
<message>*** This project requires JDK 1.8/J2SE 8 or later. ***</message>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
每当我尝试使用 mvn clean install -T 4
执行上述项目时,收集器框架项目就会被跳过并且构建失败并出现错误
Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project full-build: An Ant BuildException has occured: Warning: Could not find file /Users/tuk/code/github/eros/main/collector-framework/collector/target/collector-0.001-SNAPSHOT.jar to copy.
[ERROR] around Ant part ...<copy file="../collector-framework/collector/target/collector-0.001-SNAPSHOT.jar" tofile="./target/collector/collector-0.001-SNAPSHOT.jar"/>... @ 4:143 in /Users/tuk/code/github/eros/main/full-build/target/antrun/build-main.xml
只要我这样做就一切正常 mvn clean install
。我认为这是因为 ant-运行 在 main
模块执行完成之前 运行ning。有人可以告诉我如何让 ant-run
在并行构建的情况下等待主模块编译结束吗?
- Maven 版本 - 3.5.0
为了解决这个问题,我添加了 collector-framework
到 maven-antrun-plugin
的依赖,如下所示:-
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>collector</artifactId>
<version>0.001-SNAPSHOT</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<!-- collector -->
<copy file="../collector-framework/collector/target/collector-${project.version}.jar" tofile="./target/collector/collector-${project.version}.jar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
以上更改使 maven-antrun 等待创建收集器 jar。
我有一个 Maven 多模块项目。简化的 pom.xml
(在 full-build
下)如下所示:-
<?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>
<packaging>pom</packaging>
<groupId>com.eros</groupId>
<artifactId>full-build</artifactId>
<version>0.001-SNAPSHOT</version>
<name>full-build</name>
<profiles>
<profile>
<id>build-only</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>../../main</module>
</modules>
</profile>
<profile>
<id>copy-only</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<!-- collector -->
<copy file="../collector-framework/collector/target/collector-${project.version}.jar"
tofile="./target/collector/collector-${project.version}.jar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
main
中的简化 pom.xml
如下所示:-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.eros</groupId>
<artifactId>main</artifactId>
<version>0.001-SNAPSHOT</version>
<packaging>pom</packaging>
<name>main</name>
<modules>
<module>collector-framework</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
<message>*** This project requires JDK 1.8/J2SE 8 or later. ***</message>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
每当我尝试使用 mvn clean install -T 4
执行上述项目时,收集器框架项目就会被跳过并且构建失败并出现错误
Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project full-build: An Ant BuildException has occured: Warning: Could not find file /Users/tuk/code/github/eros/main/collector-framework/collector/target/collector-0.001-SNAPSHOT.jar to copy.
[ERROR] around Ant part ...<copy file="../collector-framework/collector/target/collector-0.001-SNAPSHOT.jar" tofile="./target/collector/collector-0.001-SNAPSHOT.jar"/>... @ 4:143 in /Users/tuk/code/github/eros/main/full-build/target/antrun/build-main.xml
只要我这样做就一切正常 mvn clean install
。我认为这是因为 ant-运行 在 main
模块执行完成之前 运行ning。有人可以告诉我如何让 ant-run
在并行构建的情况下等待主模块编译结束吗?
- Maven 版本 - 3.5.0
为了解决这个问题,我添加了 collector-framework
到 maven-antrun-plugin
的依赖,如下所示:-
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>collector</artifactId>
<version>0.001-SNAPSHOT</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<configuration>
<tasks>
<!-- collector -->
<copy file="../collector-framework/collector/target/collector-${project.version}.jar" tofile="./target/collector/collector-${project.version}.jar"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
以上更改使 maven-antrun 等待创建收集器 jar。