Maven从命令行覆盖project.version [英] maven override project.version from command line

查看:833
本文介绍了Maven从命令行覆盖project.version的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以通过命令行在maven中覆盖project.version/version变量?

I wonder if it is possible to override project.version/version variable in maven via command line?

以下内容无效:

mvn deploy -Dversion=1.0-test-SNAPSHOT  
mvn deploy -Dproject.version=1.0-test-SNAPSHOT  

在此先感谢您的帮助!

Thanks in advance for your help!

我的pom.xml是:

My pom.xml is:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>just.another.company.name</groupId>
    <artifactId>my-pom</artifactId>
    <version>1.3-SNAPSHOT</version>
    <name>My Module</name>
    <packaging>jar</packaging>
    <description>POM Project for My Module</description>
</project>

推荐答案

简单来说,您无法覆盖project.version.试试:

Simply you can't override project.version. Try:

mvn versions:set -DnewVersion=<version>

通常,我首先更新parentPom

Usually, I start by updating the parentPom

mvn versions:set -DnewVersion=1.0.3-SNAPSHOT

如果父pom包含所有子项目,这就足够了;否则,您将需要转到包含所有子项目的超级项目并执行

This would be enough if the parent pom contained all child projects if not you will need to go to a super project that contain all child project and execute

mvn versions:update-child-modules

如果parentPom存在于相对路径中,那么前面的两个步骤就足够了,否则您将需要使用新版本安装parentPom项目

Also the two previous steps will be enough if the parentPom exists in relative path if not you will need to install parentPom project with the new version

mvn install

通常,如果您没有模块依赖于另一个模块,这就足够了.如果这样做,则将其版本声明为project.version,它将自动反映

Usually this will be enough if you don't have module depend on another module. if you do, declare its version as a project.version like that and it will be reflected automatically

<version>${project.version}</version>

检查 maven版本插件文档.

这篇关于Maven从命令行覆盖project.version的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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