Maven:如何在多模块项目中包含 ${project.version} [英] Maven: How to include ${project.version} in multi-module project
问题描述
我正在使用 maven 3.2.1
mvn -version
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T09:37:52-08:00)
Maven home: /usr/local/Cellar/maven/3.2.1/libexec
Java version: 1.7.0_55, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.2", arch: "x86_64", family: "mac"
我的模块结构
projectA/
pom.xml
core/
pom.xml
business/
pom.xml
persistence/
pom.xml
rest/
pom.xml
federated_services/
pom.xml
ProjectA/pom.xml
<groupId>com.org</groupId>
<artifactId>projectA</artifactId>
<packaging>pom</packaging>
<version>${global.version}</version>
<properties>
<global.version>1.0-SNAPSHOT</global.version>
</properties>
core/pom.xml
<parent>
<artifactId>projectA</artifactId>
<groupId>com.org</groupId>
<version>${global.version}</version>
<relativePath>..</relativePath>
</parent>
一切都很好,直到这里意味着 core/xml 可以找到 ${project.version}
.但是当我这样做
Things are fine until here meaning core/xml can find ${project.version}
. But when I do
持久性/pom.xml
<parent>
<artifactId>core</artifactId>
<groupId>com.org</groupId>
<version>${global.version}</version>
<relativePath>../../</relativePath>
</parent>
pom 抱怨
[ERROR] The project com.org:persistence:${global.version} (/Users/harith/IdeaProjects/project/core/persistence/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM: Could not transfer artifact com.org:core:pom:${global.version} from/to local central mirror (http://maven.corp.org.com:9999/repository/public): Illegal character in path at index 68: http://maven.corp.org.com:9999/repository/public/com/org/core/${global.version}/core-${global.version}.pom and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]
问题
- 如何让 persistence/pom.xml 从 projectA/pom.xml 继承 ${project.version}
?
推荐答案
一般来说,就是不要在child中包含一个版本;它会继承它.如果您必须指定一个版本(Roo 因使用它不认可的有效 POM 发脾气而臭名昭著),您可以使用属性指定父版本或使用 ${project.parent.version}代码> 为孩子的版本.另请查看
versions
插件,它会立即在整个层次结构上设置版本.
Generally speaking, just don't include a version in the child; it'll inherit it. If you have to specify a version (Roo is notorious for throwing tantrums with valid POMs it doesn't approve of), you can either specify the parent version with the property or use ${project.parent.version}
for the child's version. Also look at the versions
plugin, which will set the version on a whole hierarchy at once.
这篇关于Maven:如何在多模块项目中包含 ${project.version}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!