【问题标题】:Global changes to maven surefire plugin in .m2/settings.xml.m2/settings.xml 中对 maven surefire 插件的全局更改
【发布时间】:2017-10-07 13:22:28
【问题描述】:

我想更改maven-surefire-plugin 的默认设置,而不是使用<reportFormat>brief</reportFormat>,我想使用<reportFormat>plain</reportFormat>

通常,我会通过为项目修改个人pom 来实现这一点,例如:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <redirectTestOutputToFile>true</redirectTestOutputToFile>
        <reportFormat>plain</reportFormat>
    </configuration>
</plugin>

但是,是否有可能以某种方式修改 ~/.m2/settings.xml 文件并将 &lt;reportFormat&gt;plain&lt;/reportFormat&gt; 设置为我要编译的所有 maven 项目的默认行为。 我对许多 maven 项目进行了分析,因此我更愿意在全局级别更改行为,而不是为每个单独的项目修改 pom 文件。

【问题讨论】:

  • 您应该使用公司 pom 在其中定义您希望为公司拥有的默认内容,但 settings.xml 不是它的正确位置,也不可能这样做......但是这要求您已经使用过公司的 pom 文件...

标签: java maven build pom.xml


【解决方案1】:

settings.xml 配置文件并没有达到这个详细程度。插件配置只能在 pom.xml 中指定
检查它的最佳方法是研究 settings.xml 架构:

https://maven.apache.org/xsd/settings-1.0.0.xsd

您可以看到引用“插件”一词的单个元素与构建中的插件配置无关。

根据您的要求,如果使用不当,也有其缺点的单一解决方案是使用定义插件配置的父 pom,并且所有 Maven 模块都应该作为父级从插件配置继承,并可能从其他东西继承。

如果您的应用项目使用多模块/父 pom 结构,我认为更好的解决方案是在每个多模块/父 pom 的父 pom 中声明此配置。
这样,您可以通过一组相关项目多次声明它。

【讨论】:

  • 这真的很不幸,但我想也很具体。在我认为可以更改某些全局设置之前,您的解决方案似乎与我的想法相似。无论如何,谢谢你的帮助!
  • 不客气。我很理解你的观点。有时,我们必须做一些取舍:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-18
  • 1970-01-01
  • 2013-04-01
  • 2020-08-05
  • 1970-01-01
  • 1970-01-01
  • 2020-11-24
相关资源
最近更新 更多