I am using maven 3.2.1
我使用的是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"
My module structure
我的模块结构
projectA/
pom.xml
core/
pom.xml
business/
pom.xml
persistence/
pom.xml
rest/
pom.xml
federated_services/
pom.xml
ProjectA/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
核心/ pom.xml
<parent>
<artifactId>projectA</artifactId>
<groupId>com.org</groupId>
<version>${global.version}</version>
<relativePath>..</relativePath>
</parent>
Things are fine until here meaning core/xml can find ${project.version}
. But when I do
在此之前,一切正常,这意味着core/xml可以找到${project.version}。但是当我做
persistence/pom.xml
持久性/ pom.xml
<parent>
<artifactId>core</artifactId>
<groupId>com.org</groupId>
<version>${global.version}</version>
<relativePath>../../</relativePath>
</parent>
The pom complains
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]
Question
- How can I have persistence/pom.xml inherit ${project.version}
from projectA/pom.xml?
问题-我怎样才能坚持/坚持。xml继承$ {项目。版本}显示/ pom.xml吗?
2 个解决方案
#1
4
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.
一般来说,不要在孩子身上包含一个版本;它会继承它。如果您必须指定一个版本(Roo因其不赞成使用有效的pom而出名),您可以使用属性指定父版本,或者使用${project.parent。版本}用于子版本。还可以看看版本插件,它将立即在整个层次结构上设置版本。
#2
1
First in general you can't use properties in versions:
首先,你不能在版本中使用属性:
ProjectA/pom.xml
ProjectA / pom.xml
<groupId>com.org</groupId>
<artifactId>projectA</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
Second you shouldn't need to use relative path in your childs: core/pom.xml
其次,您不需要在您的孩子中使用相对路径:core/pom.xml
<parent>
<artifactId>projectA</artifactId>
<groupId>com.org</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
This brings me to the point if you have a persistence/pom.xml
如果您有一个持久性/pom.xml,这就说明了这一点。
core com.org 1.0.0-SNAPSHOT
核心com.org 1.0.0-SNAPSHOT
Done use things like <relativePath>../../</relativePath>
this is usually an indicator that your structure is wrong.
使用
BUT: Starting with Maven 3.2.1 you can use special properties to define the versions you like. The following placeholders are allowed in versions:
但是:从Maven 3.2.1开始,您可以使用特殊的属性来定义您喜欢的版本。版本中允许使用以下占位符:
${revision}, ${changelist}, and ${sha1}
This means if you like you can use them but only with Maven 3.2.1 so you need to change it to things like this:
这意味着,如果您希望您可以使用它们,但只能使用Maven 3.2.1,那么您需要将其更改为如下所示:
ProjectA/pom.xml
ProjectA / pom.xml
<groupId>com.org</groupId>
<artifactId>projectA</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
and in core:
核心:
<parent>
<artifactId>projectA</artifactId>
<groupId>com.org</groupId>
<version>${revision}</version>
</parent>
<artifactId>core</artifactId>
But this means you need to call maven everytime like this:
但这意味着每次都需要这样调用maven:
mvn -Drevision=1.0.0-SNAPSHOT clean package
which will work. You have to be carefull if you use your project within Eclipse etc. Apart from the above i can not recommend to use it this way.
这将工作。如果您在Eclipse中使用您的项目,您必须非常小心。除此之外,我不建议您以这种方式使用它。
#1
4
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.
一般来说,不要在孩子身上包含一个版本;它会继承它。如果您必须指定一个版本(Roo因其不赞成使用有效的pom而出名),您可以使用属性指定父版本,或者使用${project.parent。版本}用于子版本。还可以看看版本插件,它将立即在整个层次结构上设置版本。
#2
1
First in general you can't use properties in versions:
首先,你不能在版本中使用属性:
ProjectA/pom.xml
ProjectA / pom.xml
<groupId>com.org</groupId>
<artifactId>projectA</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
Second you shouldn't need to use relative path in your childs: core/pom.xml
其次,您不需要在您的孩子中使用相对路径:core/pom.xml
<parent>
<artifactId>projectA</artifactId>
<groupId>com.org</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
This brings me to the point if you have a persistence/pom.xml
如果您有一个持久性/pom.xml,这就说明了这一点。
core com.org 1.0.0-SNAPSHOT
核心com.org 1.0.0-SNAPSHOT
Done use things like <relativePath>../../</relativePath>
this is usually an indicator that your structure is wrong.
使用
BUT: Starting with Maven 3.2.1 you can use special properties to define the versions you like. The following placeholders are allowed in versions:
但是:从Maven 3.2.1开始,您可以使用特殊的属性来定义您喜欢的版本。版本中允许使用以下占位符:
${revision}, ${changelist}, and ${sha1}
This means if you like you can use them but only with Maven 3.2.1 so you need to change it to things like this:
这意味着,如果您希望您可以使用它们,但只能使用Maven 3.2.1,那么您需要将其更改为如下所示:
ProjectA/pom.xml
ProjectA / pom.xml
<groupId>com.org</groupId>
<artifactId>projectA</artifactId>
<packaging>pom</packaging>
<version>${revision}</version>
and in core:
核心:
<parent>
<artifactId>projectA</artifactId>
<groupId>com.org</groupId>
<version>${revision}</version>
</parent>
<artifactId>core</artifactId>
But this means you need to call maven everytime like this:
但这意味着每次都需要这样调用maven:
mvn -Drevision=1.0.0-SNAPSHOT clean package
which will work. You have to be carefull if you use your project within Eclipse etc. Apart from the above i can not recommend to use it this way.
这将工作。如果您在Eclipse中使用您的项目,您必须非常小心。除此之外,我不建议您以这种方式使用它。