Maven问题使用修订版属性构建一个模块 [英] Maven issue to build one module using revision property

查看:63
本文介绍了Maven问题使用修订版属性构建一个模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我们尝试使用jenkins为构建(Maven 3.3.9)提供 $ {revision} 属性来部署文件. 它可以在json上为开发版本创建0.0.1-SNAPSHOT并为发行版创建0.0.1-RC正常工作,但是在开发人员机器上使用maven时存在问题. 我们有一个多模块的maven项目,其版本在parent中定义,有些模块使用其他模块作为依赖项.两者都从jenkins构建并在本地使用maven,以便与IDE集成并运行测试,然后再将其推送到存储库中. 当我们尝试构建单个模块时,maven无法识别${revision},尽管当我们提到所有模块时它可以正常工作,例如mvn clean install -pl appserver,我们看到

Recently we tried to deploy files using jenkins providing ${revision} property for the build ( Maven 3.3.9 ). It worked OK on json creating 0.0.1-SNAPSHOT for dev builds and 0.0.1-RC for releases, but we have an issue using maven on developer machines. We have multi-module maven project with version defined in parent and some modules uses others as dependencies. Both build it from jenkins and use maven locally, to integrate with IDEs and run tests before pushing it into repository. When we try to build a single module, maven does not recognize ${revision}, although it works fine when we mention all modules e.g. mvn clean install -pl appserver, we see

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>

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

但唯一有效的方法是为父级构建,该父级将构建模块及其依赖的所有模块:

but the only thing that works is a build for parent that that builds the module and all modules it depends on:

mvn clean install -pl appserver,my-kinesis-events,module1,module2,...

尽管以上方法都能奏效,但团队需要在每次需要的时候在IDE中定义自定义运行配置.

Although the above works it requires from the team to define custom run configuration in IDE, each time they need something.

有人也遇到了这个问题并找到了解决方案吗?

Did somebody also experienced this issue and found the solution?

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

Parent pom snippet: <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>

Module pom snippet: <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.

These issues have been fixed since Maven 3.5, you need however to use the maven flatten plugin to ensure that all variables are removed from your POM before publishing. Otherwise you end up having POM containing ${revision} has version.

以下博客文章.

这篇关于Maven问题使用修订版属性构建一个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆