Maven:未对pom的/project/version标记进行属性替换? [英] Maven: property substitution not done for /project/version tag of pom?

查看:372
本文介绍了Maven:未对pom的/project/version标记进行属性替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://maven.apache.org/pom.html#Properties 说属性可以在POM中的任何位置访问值".

http://maven.apache.org/pom.html#Properties says property "values are accessible anywhere within a POM".

这应该是在POM中的个地方都可以访问"吗?

Should this read "are accessible in most places within a POM"?

我可以这样指定依赖项的版本:

I can specify the version of a dependency no problem like so:

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>${junit.version}</version>
    <scope>test</scope>
</dependency>

但是项目本身的版本是这样的:

But what about the version of the project itself like so:

<project xmlns="http://maven.apache.org/POM/4.0.0" ...>

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>${myversion}</version>

    <properties>
        <myversion>8</myversion>
    </properties>

    <modules>
        <module>alpha</module>
        <module>beta</module>
    </modules>
    ...

如果我尝试使用此< version>,则不会采用值8.在这里,我在pom中定义了$ {myversion},但是如果在命令行上指定-Dmyversion = 8,情况似乎也是如此.

If I try this <version> will not take the value 8. Here I've defined ${myversion} in the pom but the same seems to be the case if I specify -Dmyversion=8 on the command line.

如果其中一个模块使用硬编码版本号指定其父级,如下所示:

If one of the modules specifies its parent with a hardcoded version number like so:

<parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <version>8</version>
</parent>

当我尝试构建时,当maven来查看模块的pom时,它将说无法找到版本8的给定父pom.

When I try to build then when maven comes to look at the module's pom it will say it cannot find the given parent pom with version 8.

但是,如果我也将父级中的版本也硬编码为8,而不是使用$ {myversion},则一切正常.

However if I hardcode version in the parent to 8 as well, rather than using ${myversion}, then everything works fine.

因此对我来说似乎不会对父pom的/project/version标记进行属性替换.

So it seems to me that property substitution does not happen for the /project/version tag of the parent pom.

是这种情况还是对我似乎看到的内容有其他解释?

Is this the case or is there some other explanation for what I seem to be seeing?

此致

/乔治

推荐答案

在Maven 2.x中,按设计不允许在/project/parent/(groupId|artifactId|version)/project/(groupId|artifactId|version)中进行属性替换.

Property substitution is not allowed in /project/parent/(groupId|artifactId|version) or in /project/(groupId|artifactId|version) by design in Maven 2.x.

所以规则是:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆