gpt4 book ai didi

java - 在 maven-surefire-plugin 中附加 argLine 参数的值

转载 作者:行者123 更新时间:2023-12-02 03:02:23 34 4
gpt4 key购买 nike

我正在使用 maven-surefire-plugin + Sonar 一起使用,我想向 maven 的 argLine 参数添加一些额外的值-surefire-插件。

所以我做到了:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>-DCRR.Webservice.isSimulated=true -D...</argLine>
</configuration>
</plugin>
...
</plugins>
</build>

但在这种情况下,我将覆盖 argLine 参数的原始值,并且 Sonar 不会生成 jacoco.exec 文件。

我可以在maven调试日志(-X)中看到argLine参数的值而不覆盖其值是-javaagent:/opt/jenkins/.../myproject-SONAR/.repository/org/jacoco/org.jacoco.agent/0.7.4.201502262128/org.jacoco.agent-0.7.4.201502262128-runtime.jar=destfile=/opt/jenkins/.../myproject-SONAR/target/jacoco.exec .

附加此参数的原始值的正确方法是什么(保留原始值+添加额外值)?

我使用的是 Apache Maven 3.5.0,Java 版本:1.8.0_131,供应商:Oracle Corporation。

最佳答案

官方文档称late replacement .

如果您执行以下操作,您将覆盖之前由其他插件设置的 argLine 参数的值,因此不要这样做:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-D... -D...</argLine>
</configuration>
</plugin>

保留现有值并添加配置的正确方法是使用 @{...} 语法:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} -D... -D...</argLine>
</configuration>
</plugin>

或者您可以在 pom.xml 文件中将 argLine 设置为 property:

<properties>
<argLine>-DCRR.Webservice.isSimulated=true -D...</argLine>
</properties>

以上两种解决方案都可以正常工作。

关于java - 在 maven-surefire-plugin 中附加 argLine 参数的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46489455/

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