如何获取命令行属性以覆盖Maven属性 [英] How to get a command-line property to overwrite a maven property

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

问题描述

我有一个pom文件,其中某些依赖项的版本号取决于在项目版本属性中指定的pom文件的设置.我可以通过命令行覆盖吗?如果可以,怎么办?

I have a pom file in which version numbers of some dependencies rely on the project version property specified in the settings of the pom file. Can I overwrite this via the command-line? If so, how?

长话短说:

我们目前正在将我们的项目过渡到Maven,但我们还没有完全完成.有多个模块仍未使用maven构建,因此它们是我们项目中的依赖项(它们通过ant内置到jar中).发布后,我们希望所有这些jar都可以构建,并包含与父项目相同的版本号.对于一个发行版,执行两个步骤(直到我们可以使用maven获得所有内容为止)

We are currently transitioning our projects to maven, but we're not all the way there yet. There are multiple modules that are still not built with maven and are therefore dependencies in our project (they are built into jars through ant). Upon release, we want all of these jars to be built and contain the same version number as the parent project. For a release, two steps are performed (until we can get everything using maven)

  1. 罐子是用正确的发行版本(12.12.4.0)构建在ant中的.
  2. maven版本插件用于将项目部署到我们的工件存储库中.

第二步,使用命令行参数指定发布版本:

In the second step command-line arguments are used to specify the release:

mvn release:prepare -DreleaseVersion=12.12.4.0 -DdevelopmentVersion=12.12.4.1-SNAPSHOT -Dtag=iv-12.12.4.0

我希望将pom文件更新为指定的版本.但是,运行此命令时,仍将使用pom文件(12.12.4.0-SNAPSHOT)中的版本.这无法通过检查快照的依赖关系和插件"步骤,并且我需要解析仍具有从maven version属性使用的12.12.4.0-SNAPSHOT版本的jar.

I would like the pom file to be updated with the version specified. However, when this command is run, the version within the pom file (12.12.4.0-SNAPSHOT) is still being used. This fails the "checking dependencies and plugins for snapshots" step and I am required to resolve my jars that still have the 12.12.4.0-SNAPSHOT version used from the maven version property.

这使我想到了一个原始问题,即如何覆盖此问题,以便版本解析为命令行上指定的版本. 其他可能使我无法解决的问题是: 在此检查之前,如何允许Maven发行插件更新pom文件? 如何跳过快照检查(不理想)

This led me to the original question of how I can override this so that the version resolves to that specified on the command line. Additional questions that could get me past this is: How to allow the maven release plugin to update the pom file before this check? How to skip the snapshot check (not desirable)

我可以在pom文件中创建一个可以覆盖的属性,但是随后我必须在pom文件中的两个位置维护版本号.

I could create a property within the pom file that I can overwrite, but then I'd have to maintain the version number in two places within the pom file.

有想法吗?

推荐答案

直接从命令行将参数放入pom中,例如:

Put parameters directly to pom from command line for example:

mvn clean install -Dtestng.version=6.3.1

示例:

     <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.test</groupId>
        <artifactId>test</artifactId>
        <version>1.0.0</version>
        <name>test</name>
        <properties>
                <testng.version>6.4</testng.version>
        </properties>

        <dependencies>
                <dependency>
                        <groupId>org.testng</groupId>
                        <artifactId>testng</artifactId>
                        <version>${testng.version}</version>
                        <scope>test</scope>
                </dependency>
        </dependencies>
</project>

如果正常运行,将使用testng版本6.4.但是,如果您像这样运行它:将使用mvn clean install -Dtestng.version=6.3.1 testng版本6.3.1.

If you run it normally testng version 6.4 will be used. But if you run it like: mvn clean install -Dtestng.version=6.3.1 testng version 6.3.1 will be used.

请参见在Jenkins中设置Maven参数

这篇关于如何获取命令行属性以覆盖Maven属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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