51

如何${project.version}为父 pom 中的托管属性解析占位符?我预计它会在全球范围内解决,因此当父 pom 具有版本 2 时,${project.version}也将解析为版本 2。

在父 pom 我有:

<groupId>my.group</groupId>
<artifactId>parent</artifactId>
<version>2</version>
<packaging>pom</packaging>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>my.group</groupId>
            <artifactId>dep</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>     

在孩子我使用

<parent>
    <groupId>my.group</groupId>
    <artifactId>parent</artifactId>
    <version>2</version>
</parent>
<version>1</version>
<artifactId>child</artifactId>

但是使用了工件my.group.dep.1.jar,而不是my.group.dep.2.jar. 因此,占位符被解析为使用托管依赖项的项目版本,而不是定义依赖项的项目版本。

这是预期的行为吗?我正在使用Maven 3.0.4。

4

1 回答 1

43

您必须在孩子中跳过<version>标签,但保留<parent><version> ... </parent>标签。

http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance

需要注意的一个因素是,这些变量是在继承后处理的,如上所述。这意味着如果父项目使用一个变量,那么它在子项目中的定义,而不是父项目,将是最终使用的那个。

于 2013-06-03T11:40:07.480 回答