Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Spotbugs into Maven Pom - Won't generate a report?

I am in the middle of trying to integrate the Maven Spotbugs plugin into my project's pom.xml file and make it so that it will generate a report in the "Project Reports" section after running the "mvn site" command. I am able to get other reports, such as PMD, CPD, and Xref to generate, but Spotbugs is given me a lot of trouble. The command line states that the report is successfully configuring, but never generating. I have what seems to be all the required dependencies, build, and report configurations. I've tried all kinds of solutions from the Spotbugs github site, the SpotBugs documentations, multiple forums and tutorials, and nothing seems to fix my problem.

Could anybody give me a very detailed step-by-step on how to incorporate the Spotbugs Maven plugin via the pom file? I am very new to Maven and could use some help! If I need to include any files, let me know that as well.

like image 319
macdoodles Avatar asked Oct 25 '25 22:10

macdoodles


1 Answers

I followed the directions at spotbugs.readthedocs.io. Add this section into project/build/plugins section of pom.xml.

<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>

Then I ran mvn spotbugs:spotbugs and it generated projectDir/target/spotbugsXml.xml. Then I ran mvn spotbugs:check and it output

[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] --------------------------------------------------------------------

Update - I had to add it to the project/reporting/plugins section as well as the build section. Now when I run mvn site it generates a Project Reports section in the target/site/index.html which includes SpotBugs.

<reporting>
  <plugins>
    <!-- SpotBugs -->
    <plugin>
      <groupId>com.github.spotbugs</groupId>
      <artifactId>spotbugs-maven-plugin</artifactId>
      <version>3.1.3</version>
    </plugin>
  </plugins>
</reporting>
like image 108
pamcevoy Avatar answered Oct 27 '25 11:10

pamcevoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!