【转】maven同时使用maven-surefire-report-plugin和maven-surefire-plugin默认将执行两次test

时间:2023-03-08 17:39:02

https://issues.apache.org/jira/browse/SUREFIRE-753

Here the pom.xml snippet how i configured the report-plugin:

      <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.9</version>
<configuration>
<outputName>failsafe-report</outputName>
<reportsDirectories>
<reportsDirectory>${project.build.directory}/failsafe-reports</reportsDirectory>
</reportsDirectories>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>report-only</report>
</reports>
</reportSet>
</reportSets>
</plugin>

This means the name of the link in the navigation must be changed as well. May be it's needed to have a supplemental configuration parameter for this or the outputName could be used instead.

maven-surefire-plugin是maven默认的test执行器。而maven-surefire-report-plugin是site生成test报表的一个插件。maven-surefire-report-plugin默认目标是report,这个将告诉maven执行test,然后搜集surefire-reports下xml生成报告。 而默认mvn site也会执行一次test。所以造成执行两次,解决办法:

< plugin >
  < groupId >org.apache.maven.plugins< /groupId >
  < artifactId >maven-surefire-report-plugin< /artifactId >
  < version >2.7< /version >
  < reportSets >
    < reportSet >
    < reports >
      < report >report-only< /report >
    < /reports >
    < /reportSet >
  < /reportSets >
< /plugin >

将其目标更改report-only,则告诉报表插件,自己不用执行test了,直接使用生命周期里test的执行 surefire-reports结果。bug新颁布已经解决了。