我有大约 400 个插件的大型 Maven (Tycho) 项目。
我们在每个 POM 文件中指定了应用程序的版本。
有没有办法只在一个地方为所有 POM:s 指定版本?
我希望有些人会这样想:
<properties>
<buildVersion>1.1.2-SNAPSHOT</buildVersion>
</properties>
....
<version>${buildVersion}</version>
我们有父 pom.xml
:
<modelVersion>4.0.0</modelVersion>
<groupId>company</groupId>
<artifactId>build.parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>pom</packaging>
那么在每个 POM 中都是对父 POM 的引用:
<parent>
<artifactId>build.parent</artifactId>
<groupId>company</groupId>
<relativePath>../build.parent/pom.xml</relativePath>
<version>1.1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>company</groupId>
<artifactId>artifact</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
最佳答案
如果您有一个父项目,您可以在父 pom 中设置版本,在子项目中您可以使用 ${project.version} 或 ${version} 引用同级库 属性。
如果你想避免在每个 child 中重复 parent 的版本:你可以这样做:
<modelVersion>4.0.0</modelVersion>
<groupId>company</groupId>
<artifactId>build.parent</artifactId>
<version>${my.version}</version>
<packaging>pom</packaging>
<properties>
<my.version>1.1.2-SNAPSHOT</my.version>
</properties>
然后在你的 child pom 中你必须这样做:
<parent>
<artifactId>build.parent</artifactId>
<groupId>company</groupId>
<relativePath>../build.parent/pom.xml</relativePath>
<version>${my.version}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>company</groupId>
<artifactId>artifact</artifactId>
<packaging>eclipse-plugin</packaging>
<dependencies>
<dependency>
<groupId>company</groupId>
<artifactId>otherartifact</artifactId>
<version>${my.version}</version>
or
<version>${project.version}</version>
</dependency>
</dependencies>
第
关于java - 具有属性的 Maven 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19123013/