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

文章介绍了从Maven2升级到Maven3时遇到的问题及解决方案。由于Maven3不支持version属性使用变量表达式,因此引入了versions-maven-plugin插件来自动更新子模块版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在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>
            
        </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这个命令,就会将所有依赖的地方全部变成新的版本号,从而帮我们完成该问题。

转载于:https://www.cnblogs.com/beiyeren/p/4275032.html

&#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-api:${person-version}, D:\workspace\git_localrepo\access-control\person\person-api\pom.xml, line 13, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-core:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-core:${person-version}, D:\workspace\git_localrepo\access-control\person\person-core\pom.xml, line 13, column 14 &#39;dependencies.dependency.(groupId:artifactId:type:classifier)&#39; must be unique: com.tplink.cdd:vigi-common-eventbus:jar -> duplicate declaration of version (?) @ com.tplink.cdd:person-core:${person-version}, D:\workspace\git_localrepo\access-control\person\person-core\pom.xml, line 74, column 21 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-grpc-client:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-grpc-client:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-grpc-client\pom.xml, line 12, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-grpc-api:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-grpc-api:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-grpc-api\pom.xml, line 12, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-grpc-client-crossregion:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-grpc-client-crossregion:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-grpc-client-crossregion\pom.xml, line 12, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-grpc-server:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-grpc-server:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-grpc-server\pom.xml, line 12, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-repository-api:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-repository-api:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-repository-api\pom.xml, line 11, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-repository-mongo:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-repository-mongo:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-repository-mongo\pom.xml, line 11, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-web:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-web:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-web\pom.xml, line 11, column 14 Some problems were encountered while building the effective model for com.tplink.cdd:person-port-cloud:jar:1.0.0 &#39;version&#39; contains an expression but should be a constant. @ com.tplink.cdd:person-port-cloud:${person-version}, D:\workspace\git_localrepo\access-control\person\person-port-cloud\pom.xml, line 13, column 14 It is highly recommended to fix these problems because they threaten the stability of your build. For this reason, future Maven versions might no longer support building such malformed projects.
最新发布
08-16
[ERROR] [ERROR] Some problems were encountered while processing the POMs: [WARNING] &#39;version&#39; contains an expression but should be a constant. @ com.kmsoft.extend:PLM-EXTEND:${kmcloud.ext.version}, E:\IDEA\plm-ext-main\pom.xml, line 10, column 14 [FATAL] Non-resolvable parent POM for com.kmsoft.extend:plm-taskPlan-server:4.0.2-E1.0: Cannot access aliyunmaven (https://maven.aliyun.com/repository/public) in offline mode and the artifact com.kmsoft.extend:PLM-EXTEND:pom:4.0.2-E1.0 has not been downloaded from it before. and &#39;parent.relativePath&#39; points at wrong local POM @ line 5, column 13 [WARNING] &#39;version&#39; contains an expression but should be a constant. @ com.kmsoft.extend:PLM-EXTEND:${kmcloud.ext.version}, E:\IDEA\plm-ext-main\pom.xml, line 10, column 14 [WARNING] &#39;version&#39; contains an expression but should be a constant. @ com.kmsoft.extend:kmwp-ext-server:${kmcloud.ext.version}, E:\IDEA\plm-ext-main\kmwp-ext-server\pom.xml, line 12, column 14 [WARNING] &#39;version&#39; contains an expression but should be a constant. @ com.kmsoft.extend:PLM-EXTEND:${kmcloud.ext.version}, E:\IDEA\plm-ext-main\pom.xml, line 10, column 14 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.kmsoft.extend:plm-taskPlan-server:4.0.2-E1.0 (E:\IDEA\plm-ext-main\plm-taskPlan-server\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for com.kmsoft.extend:plm-taskPlan-server:4.0.2-E1.0: Cannot access aliyunmaven (https://maven.aliyun.com/repository/public) in offline mode and the artifact com.kmsoft.extend:PLM-EXTEND:pom:4.0.2-E1.0 has not been downloaded from it before. and &#39;parent.relativePath&#39; points at wrong local POM @ line 5, column 13 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] h
03-14
maven执行install时出错[ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for com.jzo2o:jzo2o-seata:1.0-SNAPSHOT: Could not find artifact com.jzo2o:jzo2o-parent:pom:1.0-SNAPSHOT and &#39;parent.relativePath&#39; points at wrong local POM @ line 6, column 13 [WARNING] &#39;dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)&#39; must be unique: com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:jar -> duplicate declaration of version ${spring-cloud-alibaba.version} @ com.jzo2o:jzo2o-parent:1.0-SNAPSHOT, E:\BaiduNetdiskDownload\jzo2o\jzo2o-framework\jzo2o-parent\pom.xml, line 279, column 25 [WARNING] &#39;version&#39; contains an expression but should be a constant. @ com.jzo2o:jzo2o-knife4j-web:${project.parent.version}, E:\BaiduNetdiskDownload\jzo2o\jzo2o-framework\jzo2o-knife4j-web\pom.xml, line 14, column 14 [WARNING] &#39;dependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)&#39; must be unique: com.alibaba.cloud:spring-cloud-starter-alibaba-sentinel:jar -> duplicate declaration of version ${spring-cloud-alibaba.version} @ line 279, column 25 @ [ERROR] The build could not read 1 project -> [Help 1] [ERROR] [ERROR] The project com.jzo2o:jzo2o-seata:1.0-SNAPSHOT (E:\BaiduNetdiskDownload\jzo2o\jzo2o-framework\jzo2o-seata\pom.xml) has 1 error [ERROR] Non-resolvable parent POM for com.jzo2o:jzo2o-seata:1.0-SNAPSHOT: Could not find artifact com.jzo2o:jzo2o-parent:pom:1.0-SNAPSHOT and &#39;parent.relativePath&#39; points at wrong local POM @ line 6, column 13 -> [Help 2] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException [ERROR] [Help 2] http://cwiki.apache.org/confluence/d
03-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值