Jan*_*šta 40 java version maven
我有一个大的Maven(第谷)项目女巫约有400个插件.
我们在每个POM文件中指定了应用程序版本.
有没有办法如何为所有POM指定版本:仅在一个地方?
我希望有人会这样想:
<properties>
<buildVersion>1.1.2-SNAPSHOT</buildVersion>
</properties>
....
<version>${buildVersion}</version>
Run Code Online (Sandbox Code Playgroud)
我们有父母pom.xml:
<modelVersion>4.0.0</modelVersion>
<groupId>company</groupId>
<artifactId>build.parent</artifactId>
<version>1.1.2-SNAPSHOT</version>
<packaging>pom</packaging>
Run Code Online (Sandbox Code Playgroud)
然后在每个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>
Run Code Online (Sandbox Code Playgroud)
Fre*_*ose 28
如果您有父项目,则可以在父pom和子项中设置版本,您可以使用$ {project.version}或$ {version}属性引用同级库.
如果您想避免在每个子节点中重复父节点的版本:您可以这样做:
<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>
Run Code Online (Sandbox Code Playgroud)
然后在你的孩子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>
Run Code Online (Sandbox Code Playgroud)
心连心
Con*_*ger 14
使用该版本的属性会生成以下警告:
[WARNING]
[WARNING] Some problems were encountered while building the effective model for xxx.yyy.sandbox:Sandbox:war:0.1.0-SNAPSHOT
[WARNING] 'version' contains an expression but should be a constant. @ xxx.yyy.sandbox:Sandbox:${my.version}, C:\Users\xxx\development\gwtsandbox\pom.xml, line 8, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Run Code Online (Sandbox Code Playgroud)
如果您的问题是由于您正在切换版本而必须在多个地方更改版本,那么正确的做法是使用Maven Release Plugin来自动执行此操作.
Ger*_*ica 12
请参阅Maven - 用户论坛'version' 包含一个表达式但应该是一个常量。添加新版本的更好方法?:
这就是为什么这是一个糟糕的计划。
部署的 pom 不会解析属性值,因此依赖该 pom 的任何人都会将依赖项视为未插入 ${ } 的字符串,并且在您的构建过程中会发生很多欢闹。
在 maven 2.1.0 和/或 2.2.0 中尝试部署具有解析属性的 poms ......这超出了预期,这就是为什么不推荐这两个版本的原因,2.2.1 是推荐的 2.x 版本.
ACV*_*ACV 10
The correct answer is this (example version):
In parent pom.xml you should have (not inside properties):
<version>0.0.1-SNAPSHOT</version>
Run Code Online (Sandbox Code Playgroud)In all child modules you should have:
<parent>
<groupId>com.vvirlan</groupId>
<artifactId>grafiti</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Run Code Online (Sandbox Code Playgroud)So it is hardcoded.
Now, to update the version you do this:
mvn versions:set -DnewVersion=0.0.2-SNAPSHOT
mvn versions:commit # Necessary to remove the backup file pom.xml
Run Code Online (Sandbox Code Playgroud)
and all your 400 modules will have the parent version updated.
使用3.5或更高版本的Maven版本,您应该能够在父节中使用占位符(例如$ {revision}),并且可以使用其余的pom内部${project.version}.
实际上,您也可以省略除了parent它们之外的项目属性,因为它们将被继承.结果看起来像这样:
<project>
<parent>
<artifactId>build.parent</artifactId>
<groupId>company</groupId>
<relativePath>../build.parent/pom.xml</relativePath>
<version>${revision}</version> <!-- use placeholder -->
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>artifact</artifactId>
<!-- no 'version', no 'groupId'; inherited from parent -->
<packaging>eclipse-plugin</packaging>
...
</project>
Run Code Online (Sandbox Code Playgroud)
有关更多信息,尤其是有关如何在发布期间解析占位符的信息,请参阅Maven CI友好版本| 多模块设置.
如果您使用 Maven 3,解决此问题的一种选择是使用版本插件 http://www.mojohaus.org/versions-maven-plugin/
具体来说是命令,
mvn versions:set -DnewVersion=2.0-RELEASE
mvn versions:commit
Run Code Online (Sandbox Code Playgroud)
这会将父 pom 和子 pom 更新为 2.0-RELEASE。您可以将其作为之前的构建步骤运行。
与发布插件不同,它不会尝试与您的源代码管理系统对话
| 归档时间: |
|
| 查看次数: |
83137 次 |
| 最近记录: |