我对maven-surefire-report-plugin
有个问题。我在我的reportSet
的reporting部分中添加了一些pom.xml
配置,但它似乎没有选择这个配置。
我是引导理解,报告部分是这样的插件的方式,但我开始怀疑。
这是我的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] ------------------------------------------------------------------------
我们可以清楚地看到,一切都是错误的,从头到尾:
我是不是漏掉了这个插件应该如何工作的东西?
发布于 2020-08-08 11:08:14
整个问题是,您运行命令mvn surefire-report:report-only
,并期望激活reporting
部分。您只执行了插件,因此激活了build/plugins/plugin
中的部分,包括版本2.22.2
,而不是reporting
部分。如果要激活reporting
部分,则必须运行命令mvn site
,然后生成整个项目页。
如果我处于您的位置,并且只想生成“尽力而为”的报告,那么我将在build/plugins/plugin/maven-surefire-report-plugin
中使用与您现在在 reporting
部分中使用的配置相同的配置。
<configuration>
<linkXRef>false</linkXRef>
<outputName>test-reports/ut</outputName>
</configuration>
答案和1一样。
正确的Maven行为依赖于正确阅读文档,请参阅链接。在您的情况下,请使用参数outputName
而不是outputDirectory
(当linkXRef
设置为false或覆盖默认的linkXRef
属性project.reporting.outputDirectory
时)。
发布于 2020-10-24 20:08:26
我可能弄错了,但我相信这里可能有错误,或者文档不正确。参考资料:http://maven.apache.org/guides/mini/guide-configuring-plugins.html#configuring-reporting-plugins
在编写本报告时,其内容如下:
它只使用元素中指定的每个报告插件的元素中定义的参数,即站点总是忽略在元素中指定的每个插件元素中定义的参数。
它首先使用元素中指定的每个报告插件的元素中定义的参数;如果找不到一个参数,它将查找在其中指定的每个插件的元素中定义的参数。
给定这种配置
<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 site
和mvn sample-report:word
时所期望的行为:
[INFO] Generating "word" report --- sample-report-plugin:1.0.0-SNAPSHOT:word
[INFO] Word is fromReporting
因为:
它首先使用元素中指定的每个报告插件的元素中定义的参数;如果找不到一个参数,它将查找在其中指定的每个插件的元素中定义的参数。
我在报告中定义了单词,所以它应该总是从那里获得配置。
然而,直接调用目标的结果与文档相矛盾:
$ 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] ------------------------------------------------------------------------
发布于 2020-08-08 10:31:37
首先,使用mvn dependency:tree
查看其他插件是否有3.0.0-M5
依赖于maven-surefire-report-plugin
。
如果您找到一个,您可能必须设置一个排除(如这里),以迫使您的声明持有。
IntelliJ的想法还可以帮助您显示哪些依赖项被抑制为重复依赖项。
还要检查是否有一个概要文件(默认情况下可能是活动的),这将解释为什么忽略您的配置。
我没看到outputDirectory
,所以它的使用必须走了。例如,就像在这个例子中一样,请检查<build>
部分。
https://stackoverflow.com/questions/63250182
复制相似问题