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

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.

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>

Stumbled over the same problem and the solution of #Mack did not work for me.
The final solution for me was to create the class files first.
So instead of
mvn site
at least a
mvn compile site
is needed to create the report.

Solved - spotbugs was requiring me to include all required configurations before it worked for some reason. I believe it worked after adding the following under the reporting section of the 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>

Late to the party but following worked for me in december 2022:
mvn spotbugs:check

Related

Maven Findbugs plugin not executing with mvn site command

I'm trying to get Findbugs working with an existing/mature Maven project.
I added the following to the <plugins> tag in my pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
<configuration>
<effort>Max</effort>
<threshold>Low</threshold>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
I then see that the Findbugs plugin runs when you run mvn site. Since the build invocation for my project is aleady:
mvn clean jacoco:prepare-agent test site jxr:jxr -Dkey1=123 -Dkey2=456 -Denvironment=DEV
...I just run it like I normally do. The build succeeds and I go to my normal site summary in my browser:
No where from here can I find any "Findbugs" reports or anything that mentions Findbugs at all. When I do a grep for Findbugs (grep -rl "findbugs" .) I do see that many of my ./target/surefire-reports/TEST-*.xml files have the term "findbugs" mentioned in them.
Worth mentioning that I do not see a target/site/findbugs.html file after the successful build...
Any ideas as to where I can find HTML Findbugs output under my Site summary (or anywhere else)? Looking for a nice HTML report showing which (if any) Findbugs checks failed.
You should add the FindBugs plugin in the <plugins> section of the <reporting> section of your pom.xml:
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.5</version>
</plugin>
</plugins>
</reporting>
...
</project>
The question just states <plugins>, not sure if that could be the issue.

Jenkins error: Plugin requires Maven version 2.2.1

I have a solution in IntelliJ that builds fine on my local.
Extract from the POM:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<dependencies>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
I have installed Jenkins on my local and created a simple Maven project and pointed it to my POM file from within Jenkins.
When I build the solution from Jenkins I get the following error:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error resolving version for 'org.apache.maven.plugins:maven-surefire-plugin': Plugin requires Maven version 2.2.1
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
On Jenkins I have installed:
Maven Integration plugin
2.15.1
Any ideas / advice would be appreciated.
My own silly mistake. Had to specify the Maven and Java JDK under:
Manage Jenkins --> Global Tool Configuration
After this everything worked.

Configure webXml in IntelliJ maven-war-plugin

In the Maven Projects tools window, I see that the maven-war-plugin:2.1.1 is installed but this is grayed out. When I run the war:war goal, I get the following warning:
[INFO] Building war:
C:\Users\Klaus\IdeaProjects\JerseyTestRestWebApp\target\tut-test-rest-api.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which
will be ignored (webxml attribute is missing from war task, or
ignoreWebxml attribute is specified as 'true
I am using IntelliJ 14.1. How does one go about setting this parameter?
Try adding this as your build configuration and it should clear up the error your seeing.
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>

A: Can't generate reports for Maven site (Maven 3.0.x)

I just want to include basic reports in my Maven site. I've included this in my POM:
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</reporting>
...
</project>
And this included in my site descriptor, index.xml:
<project>
...
<body>
<menu ref="reports" />
</body>
</project>
When I use mvn site:run none of the reports are generated, and the menu isn't generated in the navigation. The only way I can generate reports is with direct command line calls, like mvn project-info-reports. I can't get them on the site. All the help for Maven sites seems to be from 2010 so it's hard to figure out what's accurate. Here's what happens when I use clean site:run -Dport=8081:
[INFO] ------------------------------------------------------------------------
[INFO] Building travelagentservice-client 1.0.0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-site-plugin:2.2:run (default-cli) # travelagentservice-client ---
2014-06-10 15:41:30.812::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Parent project loaded from repository: choicehotels:corporate-pom:pom:2.1.0.0
[INFO] Starting Jetty on http://localhost:8081/
2014-06-10 15:41:30.960::INFO: jetty-6.1.5
2014-06-10 15:41:30.158::INFO: NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
2014-06-10 15:41:30.264::INFO: Started SelectChannelConnector#0.0.0.0:8081
Solution I figured out: I needed to specify the version of site I was using. It has to be 3.3.
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
like any plugin, you should specify a version in your pom
yes, maven-site-plugin 3.x is absolutely required for use with Maven 3: see http://maven.apache.org/plugins/maven-site-plugin/maven-3.html
if you run mvn site with no plugin version, you should get a warning

Cobertura maven plugin incorrect version

I am using cobertura and when I specify version 2.5 it downloads 1.9. Why?
My pom:
org.codehaus.mojo
cobertura-maven-plugin
2.5.2
za/co/c2d/*/.class
clean
pre-site
clean
instrument
site
instrument
cobertura
<reporting>
<plugins>
<plugin>
<!-- use mvn cobertura:cobertura to generate cobertura reports -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
Output:
[INFO] --- cobertura-maven-plugin:2.5.2:instrument (default-cli) # services ---
Downloading: http://repo1.maven.org/maven2/net/sourceforge/cobertura/cobertura/1.9.4.1/cobertura-1.9.4.1.pom
When I run this it then breaks with
[ERROR] net.sourceforge.cobertura.javancss.parser.ParseException: Encountered " ">" "> ""
As I understand it, this was fixed in version 2.0.2.
Sure you can't you can't specify version inside brackets ... could you explain more about project hierarchy ? and your full pom.xml ?
This is because you are specifying the version of the cobertura-maven-plugin , which is a different jar from cobertura package
The plugin 2.5.2 uses internally cobertura version 1.9.4.1 as stated in http://mojo.codehaus.org/cobertura-maven-plugin/

Resources