将 Spotbugs 集成到 Maven Pom - 不会生成报告?
Integrating Spotbugs into Maven Pom - Won't generate a report?
我正在尝试将 Maven Spotbugs 插件集成到我项目的 pom.xml 文件中,并使其在 [=18= 之后的 "Project Reports" 部分中生成报告] "mvn site" 命令。我能够生成其他报告,例如 PMD、CPD 和 Xref,但 Spotbugs 给我带来了很多麻烦。命令行表明报告已成功配置,但从未生成。我似乎拥有所有必需的依赖项、构建和报告配置。我已经尝试了 Spotbugs github 站点、SpotBugs 文档、多个论坛和教程中的各种解决方案,但似乎没有任何方法可以解决我的问题。
谁能给我一个非常详细的分步说明,说明如何通过 pom 文件合并 Spotbugs Maven 插件?我是 Maven 的新手,需要一些帮助!如果我需要包含任何文件,也请告诉我。
我按照 spotbugs.readthedocs.io 的指示进行操作。将此部分添加到 pom.xml
的 project/build/plugins 部分。
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>3.1.3</version>
</dependency>
</dependencies>
</plugin>
然后我 运行 mvn spotbugs:spotbugs
并且它生成了 projectDir/target/spotbugsXml.xml
。然后我 运行 mvn spotbugs:check
它输出
[INFO] --- spotbugs-maven-plugin:3.1.3:check (default-cli) @ my-project ---
[INFO] BugInstance size is 0
[INFO] Error size is 0
[INFO] No errors/warnings found
[INFO] --------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------
[INFO] Total time: 6.731 s
[INFO] Finished at: 2018-05-25T16:31:35-04:00
[INFO] --------------------------------------------------------------------
更新 - 我必须将它添加到 project/reporting/plugins 部分以及构建部分。现在,当我 运行 mvn site
它在 target/site/index.html
中生成一个 Project Reports
部分,其中包括 SpotBugs。
<reporting>
<plugins>
<!-- SpotBugs -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
</plugin>
</plugins>
</reporting>
已解决 - spotbugs 出于某种原因要求我在它工作之前包括所有必需的配置。我相信它在 pom 的报告部分下添加以下内容后有效:
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs.version}</version>
<configuration>
<effort>Max</effort>
<threshold>Default</threshold>
<spotbugsXmlOutput>true</spotbugsXmlOutput>
<spotbugsXmlOutputDirectory>target/site</spotbugsXmlOutputDirectory>
<skipEmptyReport>false</skipEmptyReport>
<encoding>${project.build.sourceEncoding}</encoding>
<includeTests>true</includeTests>
<classFilesDirectory>${project.build.outputDirectory}</classFilesDirectory>
<spotbugs.xmlOutput>true</spotbugs.xmlOutput>
<plugins>
<plugin>
<groupId>jp.skypencil.findbugs.slf4j</groupId>
<artifactId>bug-pattern</artifactId>
<version>1.4.0</version>
</plugin>
</plugins>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>spotbugs</report>
</reports>
</reportSet>
</reportSets>
</plugin>
偶然发现了同样的问题,@Mack 的解决方案对我不起作用。
我的最终解决方案是先创建 class 个文件。
所以不用
mvn site
至少一个
mvn compile site
需要创建报告。
我正在尝试将 Maven Spotbugs 插件集成到我项目的 pom.xml 文件中,并使其在 [=18= 之后的 "Project Reports" 部分中生成报告] "mvn site" 命令。我能够生成其他报告,例如 PMD、CPD 和 Xref,但 Spotbugs 给我带来了很多麻烦。命令行表明报告已成功配置,但从未生成。我似乎拥有所有必需的依赖项、构建和报告配置。我已经尝试了 Spotbugs github 站点、SpotBugs 文档、多个论坛和教程中的各种解决方案,但似乎没有任何方法可以解决我的问题。
谁能给我一个非常详细的分步说明,说明如何通过 pom 文件合并 Spotbugs Maven 插件?我是 Maven 的新手,需要一些帮助!如果我需要包含任何文件,也请告诉我。
我按照 spotbugs.readthedocs.io 的指示进行操作。将此部分添加到 pom.xml
的 project/build/plugins 部分。
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
<dependencies>
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs</artifactId>
<version>3.1.3</version>
</dependency>
</dependencies>
</plugin>
然后我 运行 mvn spotbugs:spotbugs
并且它生成了 projectDir/target/spotbugsXml.xml
。然后我 运行 mvn spotbugs:check
它输出
[INFO] --- spotbugs-maven-plugin:3.1.3:check (default-cli) @ my-project ---
[INFO] BugInstance size is 0
[INFO] Error size is 0
[INFO] No errors/warnings found
[INFO] --------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------
[INFO] Total time: 6.731 s
[INFO] Finished at: 2018-05-25T16:31:35-04:00
[INFO] --------------------------------------------------------------------
更新 - 我必须将它添加到 project/reporting/plugins 部分以及构建部分。现在,当我 运行 mvn site
它在 target/site/index.html
中生成一个 Project Reports
部分,其中包括 SpotBugs。
<reporting>
<plugins>
<!-- SpotBugs -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.3</version>
</plugin>
</plugins>
</reporting>
已解决 - spotbugs 出于某种原因要求我在它工作之前包括所有必需的配置。我相信它在 pom 的报告部分下添加以下内容后有效:
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>${spotbugs.version}</version>
<configuration>
<effort>Max</effort>
<threshold>Default</threshold>
<spotbugsXmlOutput>true</spotbugsXmlOutput>
<spotbugsXmlOutputDirectory>target/site</spotbugsXmlOutputDirectory>
<skipEmptyReport>false</skipEmptyReport>
<encoding>${project.build.sourceEncoding}</encoding>
<includeTests>true</includeTests>
<classFilesDirectory>${project.build.outputDirectory}</classFilesDirectory>
<spotbugs.xmlOutput>true</spotbugs.xmlOutput>
<plugins>
<plugin>
<groupId>jp.skypencil.findbugs.slf4j</groupId>
<artifactId>bug-pattern</artifactId>
<version>1.4.0</version>
</plugin>
</plugins>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>spotbugs</report>
</reports>
</reportSet>
</reportSets>
</plugin>
偶然发现了同样的问题,@Mack 的解决方案对我不起作用。
我的最终解决方案是先创建 class 个文件。
所以不用
mvn site
至少一个
mvn compile site
需要创建报告。