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

查看:30
本文介绍了如何获取命令行属性以覆盖 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 构建到 jars 中的).发布时,我们希望构建所有这些 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)中的版本.这使检查快照的依赖项和插件"步骤失败,我需要解决仍然使用 12.12.4.0-SNAPSHOT 版本的 jar 包,这些版本是从 Maven 版本属性使用的.

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 version 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天全站免登陆