默认配置后,maven只为源类输出Checkstyle report,而不是Junit测试类。注意我没有找到万无一失的测试报告输出。
来自pom.xml:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<configLocation>src/main/resources/apcheckstyle.xml</configLocation>
<module name="LineLength">
<property name="max" value="120"/>
</module>
</configuration>
</plugin>
</plugins>
我将junit的依赖范围从测试更改为编译:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>compile</scope>
</dependency>
Maven配置为使用mvn网站插件生成checkstyle报告。 我尝试添加用户属性includeTestResources为true,但这没有帮助。文档声明默认值为true,因此我将其取出。
这是checkstyle生成期间的maven输出。
来自javadocs的:
生成C:\ Users \ Administrator \ Projects \ lht657aws \ target \ site \ testapidocs \ help-doc.html ...
checkstyle插件运行:
[INFO] Generating&#34; Checkstyle&#34;报告--- maven-checkstyle-plugin:2.17
[INFO] Checkstyle 6.11.2使用src / main / resources / apcheckstyle.xml规则集报告了210个错误。
正在关注这个问题 - ?正在处理src下的所有java,只是跳过了测试中的java:
[警告]无法找到源XRef链接到 - DISABLED
[INFO]生成&#34;依赖关系&#34;报告--- maven-project-info-reports-plugin:2.9
答案 0 :(得分:3)
将Maven Surefire报告插件添加到您的pom XML
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<outputDirectory>path/to/the/report</outputDirectory>
</configuration>
</plugin>
将目标surefire-report:report
添加到您的maven通话
请参阅此处的文档:Maven Surefire Report Plugin
修改强>
我误解了这个问题,尝试将此部分添加到您的pom所需的配置中。
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<reportSets>
<reportSet>
<id>main_checks</id>
<reports>
<report>checkstyle</report>
</reports>
<configuration>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
<configLocation>config/maven_checks.xml</configLocation>
<outputDirectory>${project.reporting.outputDirectory}/main-checks/</outputDirectory>
</configuration>
</reportSet>
<reportSet>
<id>test_checks</id>
<reports>
<report>checkstyle</report>
</reports>
<configuration>
<sourceDirectory></sourceDirectory>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<configLocation>config/sun_checks.xml</configLocation>
<outputDirectory>${project.reporting.outputDirectory}/test-checks/</outputDirectory>
</configuration>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
答案 1 :(得分:0)
Maven sure fire插件用于生成测试报告。请参阅此处的其他文档:
http://maven.apache.org/surefire/maven-surefire-report-plugin/
您需要在POM.xml中包含此插件,并提供创建报告的路径(通常是项目中的目录)。在进行构建时,请确保包含此目标。