maven2 up to maven3的'version' contains an expression but should be a constant

在Maven2时,为了保障版本一致,一般之前我们的做法时:

Parent Pom中

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>cy.nad.cyg</groupId>
    <artifactId>pay</artifactId>
    <version>${myproject.version}</version>
    <packaging>pom</packaging>
    <name>pay-parent</name>

    <modules>
        <module>pay-web</module>
        <module>pay-manage</module>
        <module>pay-dao</module>
    </modules>

    <properties>
        <myproject.version>3.0.2</myproject.version>

在子module中

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>pay</artifactId>
        <groupId>cy.nad.cyg</groupId>
        <version>${myproject.version}</version>
    </parent>
    <artifactId>pay-web</artifactId>
    <packaging>war</packaging>
    <name>pay-web</name>
    <properties>
        <sso-client.version>0.0.3</sso-client.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>cy.nad.cyg</groupId>
            <artifactId>pay-dao</artifactId>
            <version>${project.version}</version>
        </dependency>

但是升级到maven3之后,会出这个问题:

[WARNING] Some problems were encountered while building the effective model for cy.nad.cyg:pay-web:war:3.0.2
[WARNING] 'version' contains an expression but should be a constant. @ cy.nad.cyg:pay:${myproject.version}, D:\workspace\idea\pay\pom.xml, line 7, column 14

这是因为Maven3 不允许出现version为非常量值的情况,我们就需要第三方插件来帮我们自动完成升级版本的工作。

参见下文:

http://mojo.codehaus.org/versions-maven-plugin/examples/update-child-modules.html

这个插件等于只需要我们在parent pom中变更一下版本号,然后执行

mvn -N versions:update-child-modules这个命令,就会将所有依赖的地方全部变成新的版本号,从而帮我们完成该问题。

posted @ 2015-02-05 15:47  beiyeren  阅读(18893)  评论(0编辑  收藏  举报