最近我们尝试使用 jenkins 部署文件,提供 ${revision}
构建的属性( Maven 3.3.9 )。
它在创建 0.0.1-SNAPSHOT
的 json 上工作正常用于开发版本和 0.0.1-RC
对于发布,但我们在开发人员机器上使用 maven 时遇到问题。
我们有多模块 Maven 项目,其版本在父项中定义,一些模块使用其他模块作为依赖项。两者都从 jenkins 构建并在本地使用 maven,与 IDE 集成并在将其推送到存储库之前运行测试。
当我们尝试构建单个模块时,maven 无法识别 ${revision}
,尽管当我们提到所有模块时它工作正常,例如mvn clean install -pl appserver
, 我们看Failed to execute goal on project appserver: Could not resolve dependencies for project com.org:appserver:war:0.0.1-local: Failed to collect dependencies at com.org:my-kinesis-events:jar:0.0.1-local: Failed to read artifact descriptor for com.org:my-kinesis-events:jar:0.0.1-local: Could not transfer artifact com.org:my-parent:pom:${revision} from/to central: Failed to transfer .../repository/maven-central/com/org/my-parent/${revision}/my-parent-${revision}.pom. Error code 500, Server Error -> [Help 1]
我们尝试使用:
-Drevision=0.0.1-local
<profile>
<id>default-version</id>
<activation>
<property>
<name>!revision</name>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<revision>0.0.1-local</revision>
<project.version>0.0.1-local</project.version>
</properties>
</profile>
但唯一有效的是构建模块及其依赖的所有模块的父级构建:
mvn clean install -pl appserver,my-kinesis-events,module1,module2,...
虽然上述工作需要团队在 IDE 中定义自定义运行配置,但每次他们需要一些东西。
是否有人也遇到过这个问题并找到了解决方案?
父 pom 片段:
<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.org</groupId>
<artifactId>my-parent</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>My Parent module</name>
<modules>
<module>../my-tools</module>
<module>my-kinesis-events</module>
....
</modules>
.....
</project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>my.org</groupId>
<artifactId>my-kinesis-events<</artifactId>
<version>${project.version}</version>
<dependency>
<dependencies>
</dependencyManagement>
模块 pom 片段:
<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>
<artifactId>appServer</artifactId>
<parent>
<groupId>com.org</groupId>
<artifactId>my-dsp</artifactId>
<version>${revision}</version>
<relativePath>..</relativePath>
</parent>
<packaging>war</packaging>
<name>AppServerAPI</name>
<description>Application Server</description>
<dependencies>
<dependency>
<groupId>com.org</groupId>
<artifactId>my-openrtb</artifactId>
</dependency>
.....
</dependencies>
....
</project>
最佳答案
这些问题自 Maven 3.5 以来已得到修复,但是您需要使用 maven flatten 插件来确保在发布之前从您的 POM 中删除所有变量。否则,您最终会得到包含 ${revision} 的 POM 版本。
这在下面的blog post中得到了巧妙的解释。 .
关于java - 使用修订属性构建一个模块的 Maven 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41086512/