maven-surefire-report-plugin 没有获取其配置

maven-surefire-report-plugin not picking up its configuration

maven-surefire-report-plugin 我遇到了问题。我在 pom.xml 的报告部分添加了一些 reportSet 配置,但它似乎没有选择此配置。

我曾 lead to understand 报告部分是寻找此类插件的方式,但我开始对此表示怀疑。

这是我的 pom.xml 报告部分:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.22.2</version>

            <configuration>
                <linkXRef>false</linkXRef>
            </configuration>

            <reportSets>
                <reportSet>
                    <id>aggregated-unit-test-report</id>

                    <configuration>
                        <outputDirectory>${project.reporting.outputDirectory}/test-reports/ut</outputDirectory>
                    </configuration>

                    <reports>
                        <report>report-only</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>

这是(部分)我从 运行 mvn surefire-report:report-only -X 那个模块上得到的:

// Cropped for brevity
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-surefire-report-plugin:3.0.0-M5:report-only' with basic configurator -->
[DEBUG]   (f) aggregate = false
[DEBUG]   (f) alwaysGenerateSurefireReport = true
[DEBUG]   (f) inputEncoding = ISO-8859-1
[DEBUG]   (f) linkXRef = true
[DEBUG]   (f) outputDirectory = C:\Users\francois.dupire\workspace\forhrm\libs\framework\coverage\target\site
[DEBUG]   (f) outputName = surefire-report
[DEBUG]   (f) project = MavenProject: be.formatech.forhrm.framework:framework-coverage:1.0.0-SNAPSHOT @ C:\Users\francois.dupire\workspace\forhrm\libs\framework\coverage\pom.xml
[DEBUG]   (f) reactorProjects = [MavenProject: be.formatech.forhrm.framework:framework-coverage:1.0.0-SNAPSHOT @ C:\Users\francois.dupire\workspace\forhrm\libs\framework\coverage\pom.xml]
[DEBUG]   (f) showSuccess = true
[DEBUG]   (f) skipSurefireReport = false
[DEBUG]   (f) xrefLocation = C:\Users\francois.dupire\workspace\forhrm\libs\framework\coverage\target\site\xref-test
[DEBUG] -- end configuration --
[WARNING] Unable to locate Test Source XRef to link to - DISABLED
// Cropped for brevity
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.976 s
[INFO] Finished at: 2020-08-04T17:24:57+02:00
[INFO] Final Memory: 13M/32M
[INFO] ------------------------------------------------------------------------

我们可以清楚地看到一切都错了,从头到尾:

我是否遗漏了有关此插件应该如何工作的信息?

首先,使用 mvn dependency:tree 查看是否有任何其他插件对 maven-surefire-report-plugin 具有 3.0.0-M5 依赖性。
如果您找到了,您可能必须 才能强制您的声明成立。
IntelliJ IDEA 还可以帮助您显示哪些依赖项被抑制为重复项。

还要检查是否有一个配置文件(默认情况下可能处于活动状态)可以解释为什么您的配置被忽略。
我没有看到 any obvious bug report on a wrong outputDirectory, so its usage must be off. For instance, as in this example,请检查您的 <build> 部分。

  1. 版本是 3.0.0-M5 而我指定的是 2.22.2

整个问题是您 运行 命令 mvn surefire-report:report-only 并且您希望 reporting 部分被激活。您除了执行插件外什么也没做,因此 build/plugins/plugin 中的部分被激活,包括版本 2.22.2 而不是 reporting 部分。如果您想激活 reporting 部分,您必须 运行 命令 mvn site 然后将生成整个项目页面。

如果我处于你的位置并且只想生成 Surefire 报告,那么我会在 build/plugins/plugin/maven-surefire-report-plugin 中使用与你现在在 reporting 部分中相同的配置.

    <configuration>
        <linkXRef>false</linkXRef>
        <outputName>test-reports/ut</outputName>
    </configuration>
  1. linkXRef 参数是 true 而不是 false

与 1 相同的答案。

  1. 输出目录也没有改变

正确的 Maven 行为依赖于正确阅读文档,请参阅 link。 请在您的情况下使用参数 outputName 而不是 outputDirectory(当 linkXRef 设置为 false 或覆盖默认的 Maven 属性 project.reporting.outputDirectory).

我可能弄错了,但我相信要么这里有错误,要么文档不正确。引用:http://maven.apache.org/guides/mini/guide-configuring-plugins.html#configuring-reporting-plugins

在撰写本文时,内容为:

  • mvn 站点

It uses only the parameters defined in the element of each reporting Plugin specified in the element, i.e. site always ignores the parameters defined in the element of each plugin specified in .

  • mvn aplugin:areportgoal

It uses firstly the parameters defined in the element of each reporting Plugin specified in the element; if a parameter is not found, it will look up to a parameter defined in the element of each plugin specified in .

鉴于此配置

<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>io.anemortalkid</groupId>
                    <artifactId>sample-report-plugin</artifactId>
                    <version>1.0.0-SNAPSHOT</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.9.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>io.anemortalkid</groupId>
                <artifactId>sample-report-plugin</artifactId>
                <configuration>
                    <word>fromBuild</word>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>io.anemortalkid</groupId>
                <artifactId>sample-report-plugin</artifactId>
                <configuration>
                    <word>fromReporting</word>
                </configuration>
            </plugin>
        </plugins>
    </reporting>

还有魔力报告

@Mojo(name = "word", defaultPhase = LifecyclePhase.SITE, threadSafe = true)
public class SampleReport extends AbstractMavenReport {

  @Parameter private String word;

  protected void executeReport(Locale locale) throws MavenReportException {
    getLog().info("Word is " + word);
  }

  public String getOutputName() {
    return "word.html";
  }

  public String getName(Locale locale) {
    return "word";
  }

  public String getDescription(Locale locale) {
    return "Prints a word from config";
  }
}

我在执行 mvn sitemvn sample-report:word 时期望的行为同时打印:

[INFO] Generating "word" report          --- sample-report-plugin:1.0.0-SNAPSHOT:word
[INFO] Word is fromReporting

开始于:

It uses firstly the parameters defined in the element of each reporting Plugin specified in the element; if a parameter is not found, it will look up to a parameter defined in the element of each plugin specified in .

我在报告中定义了 word,所以它应该总是从那里获取配置。

然而,直接调用目标的结果与文档相矛盾:

$ mvn sample-report:word
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< io.anemortalkid:config-print >--------------------
[INFO] Building config-print 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- sample-report-plugin:1.0.0-SNAPSHOT:word (default-cli) @ config-print ---
[INFO] Word is fromBuild
[INFO] ------------------------------------------------------------------------

可重现样本:https://github.com/AnEmortalKid/sample-report-plugin

创建https://issues.apache.org/jira/browse/MNG-7006确认