gpt4 book ai didi

java - Maven - 将默认参数更改为定义的其他 pom.xml

转载 作者:行者123 更新时间:2023-12-01 10:11:47 29 4
gpt4 key购买 nike

我有一个使用 Maven 运行的 testNG 测试发行版。每当我需要默认测试分发时,我都可以这样做,每当我只需要几个或仅一个测试时,我可以在命令行中更改类似 -DoverallParams 的内容(尽管名称已更改)。

<properties>
<param1>x</param1>
<param2>y</param2>
<param3>z</param3>
<defaultParams>${param1},${param2}</defaultParams>
<defaultParams2>${param1},${param3}</defaultParams2> <-This does not exist yet!
<overallParams>${defaultParams}</overallParams>
</properties>

我现在需要对不同的平台使用一组不同的测试,而无需复制或分支项目。因此,我们的想法是添加一个 defaultPrams2 并以某种方式在命令行中选择它。

问题:

有什么方法可以在命令行中添加一些内容,让我选择 defaultParams2 作为 overallParams 吗?更简单的是,有没有办法在命令行中引用 pom 属性?您对如何做到这一点还有其他想法吗?

最佳答案

Is there any way to have something in the command line which would make me select defaultParams2 as the overallParams?

是的,Maven profiles可以在这方面帮助您。

您的 pom 中可以包含以下内容:

<profiles>
<profile>
<id>meaningful-name-here</id>
<properties>
<overallParams>${defaultParams2}</overallParams>
</properties>
</profile>
</profiles>

然后您可以从命令行调用 Maven,如下所示:

mvn clean install -Pmeaningful-name-here

基本上,-P<id>选项将激活上面的配置文件,然后覆盖 overallParams 的值属性并因此切换到 defaultParams2运行时和按需的值(value)。

这种方法比以下方法更不容易出错:

mvn clean install -DoverallParams=params

您需要每次键入所需参数(因此按需覆盖 overallParams 的值)。只需选择一个比 meaningful-name-here 更好(且更短)的 ID :)

is there a way to reference a pom property in command line?

是的,通过显式覆盖 ( -D ) 或通过配置文件 ( -P ),如上所述。

关于java - Maven - 将默认参数更改为定义的其他 pom.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36085790/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com