本文介绍了带有属性的 Maven 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约 400 个插件的大型 Maven (Tycho) 项目.

I have big Maven (Tycho) project witch about 400 plug-ins.

我们在每个 POM 文件中都指定了应用程序的版本.

We have specified version of application in each POM file.

有没有办法只在一个地方为所有 POM:s 指定版本?

Is there a way how to specify the version for all POM:s only on one place?

我希望有人会这样想:

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

Then in each POM is reference to parent 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>

推荐答案

请参阅 Maven - Users 论坛 'version' 包含一个表达式但应该是一个常数.添加新版本的更好方法?:

See the Maven - Users forum 'version' contains an expression but should be a constant. Better way to add a new version?:

这就是为什么这是一个糟糕的计划.

部署的pom不会解析属性值,所以任何依赖该 pom 的人都会将依赖项视为未插入 ${ } 的字符串,并且会在您的构建过程.

the pom that gets deployed will not have the property value resolved, so anyone depending on that pom will pick up the dependency as being the string uninterpolated with the ${ } and much hilarity will ensue in your build process.

在 maven 2.1.0 和/或 2.2.0 中尝试部署 pom已解决的属性......这超出了预期,这就是为什么那些不推荐使用两个版本,2.2.1 是推荐的 2.x 版本.

in maven 2.1.0 and/or 2.2.0 an attempt was made to deploy poms with resolved properties... this broke more than expected, which is why those two versions are not recommended, 2.2.1 being the recommended 2.x version.

这篇关于带有属性的 Maven 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 07:56