Configuring emma with maven to generate xml or text reports - maven

I am trying to add emma to project build. I went through the tutorials here -
Maven emma plugin
But i am not able to figure out how do I specify what kind of reports to generate - i mean txt or xml. How do I add this part to the maven build so that when the POM file builds it generates either txt or xml report in some specific directory.

The functionality has been included in the development version of the Sonatype Emma Plugin, emma-maven-plugin-1.3-SNAPSHOT, but it has not been released yet.
https://github.com/sonatype/emma-maven-plugin/pull/1
and
https://github.com/sonatype/emma-maven-plugin/pull/2
Note that this is not the same as the Codehaus Emma plugin that you referenced in your question, but the change should be minimal.
Once version 1.3 is released, you should be able to put the following in the reporting section of your pom.xml file to get the full range of output formats:
<reporting>
<plugins>
<plugin>
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<formats>html,xml,txt</formats>
</configuration>
</plugin>
</plugins>
</reporting>

You can use the emma4it-maven-plugin for reporting. The 1.3 version has some issue.
But the 1.4-SNAPSHOT works fine.
Here is the git link for the same : https://github.com/billmag/emma4it-maven-plugin.git
Clone the repo and do a mvn clean install.
Also you can use 1.2 version in case you don't want to use a SNAPSHOT version.
The configuration in pom for reporting is as follows:
<reporting>
<plugins>
<plugin>
<groupId>org.sonatype.maven.plugin</groupId>
<artifactId>emma4it-maven-plugin</artifactId>
<version>1.4-SNAPSHOT</version>
<configuration>
<verbosity.level>verbose</verbosity.level>
<metadatas>coverage.em path</metadatas>
<instrumentations>coverage.ec path</instrumentations>
<reportDirectory>target/emma/</reportDirectory>
<baseDirectory>${project.basedir}/target</baseDirectory>
<formats>xml,html</formats>
</configuration>
</plugin>
</plugins>
</reporting>
Command to get the reports
mvn org.sonatype.maven.plugin:emma4it-maven-plugin:1.4-SNAPSHOT:report

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.

fb-contrib bugs appears as unknown bug patterns

I am using FindBugs with maven, using the following configuration:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.3</version>
<configuration>
<xmlOutput>true</xmlOutput>
<xmlOutputDirectory>target/site</xmlOutputDirectory>
<plugins>
<plugin>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>6.2.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</reporting>
I run:
mvn clean
mvn package
mvn site
mvn findbugs:gui
And I get all errors listed in GUI, but I realized that all bugs detected by fb-contrib plugin are shown under Experimental\Testing prototype and incomplete bug pattern\Unknown bug pattern and FindBugs doesn't show any info about bug pattern.
Is this correct? Is it possible to get bug pattern info as with the FindBugs pattern bugs?
Thanks in advance.
findbugs-maven-plugin doesn't supply the configured plugins, when it launches the FindBugs GUI (Issue #37). I've submitted a pull request fixing this, you could grab my fork and build the plugin.
Alternatively, if your plugins don't change often, you could add them manually in the GUI: open the menu Edit -> Preferences, switch to the Plugins tab, install the plugin jar from the local Maven repository. At least on Windows the plugin configuration persists between GUI launches via the registry.

how to exclude jar file from getting installed using maven-install-plugin?

I have a jar file created using maven-jar-plugin.
Is there a way to skip this jar file from getting installed in repository?
Thanks in advance.
Try this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
The reason this works is that the install plugin's only job is to take your artifact(s) and install them in your local repo.
In Maven, there are main artifacts and attached artifacts. I am not sure if you can suppress installation of the main artifact and only install the attached artifact, since assemblies are not required to provide a POM.
If this is what you really want to achieve, I would suggest breaking out the assembly to a separate artifact (with <packaging>pom</packaging>), have it depend on the jar-artifact you are trying to exclude and simply install that.

Checkstyle working in Maven, but not working in Jenkins

I am using Maven, Maven checkstyle plugin, Jenkins and Jenkins checkstyle plugin.
I have 7 projects total. 1 parent and 6 child projects.
I have the following 3 scenarios :
Checkstyle report for all project.n parent pom i declared checkstyle plugin in tag:
I run mvn clean site command
It working both ways in eclipse with maven. and in Jenkins also.
Giving checkstyle reports for all 7 projects.
Checkstyle report for all project except 2 project.
I deleted part in parent pom and i added
I added in remaining 4 projects, i declared checkstyle plugin in tag.
It working in eclipse but not working in Jenkins.
Please give solution
My code:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<configLocation>../parent-project/checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>
3.
I deleted checkstyle plugin in parent
I added checkstyle plugin in 4 needed projects same above code.
In remaining 2 child projects I added like this.
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
I run 'mvn clean site'
It working in Maven as expected but not working in Jenkins.
What I mean by 'not working in Jenkins' is that I installed checkstyle plugin in Jenkins, In the Jenkins job i selected 'Publish Checkstyle analysis results' check box. In scenario-1 i am able to see the checkstyle link in the jenkins job page. And if i click on that all code violations reports are appearing. In other scenarios (2,3) the Checkstyle link also not appearing.
Just found the solution.
In the project configure menu, in the "Goals and options" field you need to add 'site' without the ' characters. In my "Goals and options" field I had: clean install. This did not run checkstyle. But then I changed it to: clean install site. And now checkstyle runs!
Hope this solves your problem.
Edit:
My pom.xml has been extended with the tag:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.10</version>
</plugin>
</plugins>
to run checkstyle. Try using only that for checkstyle and then run the project again.

How to configure FindBugs to run only on one project in a multi-module maven project

I use the findbugs-maven-plugin to check for bugs with maven. My maven project is a multi-module project that roughly looks as follows:
java-module
pom.xml
src/ ...
pom.xml
scala-module
pom.xml
src/ ...
I use Jenkins to build and test the project, and Jenkins runs goal findbugs:findbugs in the top-most directory. Since FindBugs reports many spurious warnings for code that is generated by the Scala compiler, I would like to tell FindBugs not to analyze the code in scala-module. However, when I run findbugs:findbugs in the top-most directory, it always analyzes all classes in java-module and scala-module. How can I tell maven to ignore scala-module as a whole? I know about FindBugs exclude filters but I would to have a configuration option for FindBugs that tells it to simply not analyze the code in a certain submodule.
FindBugs is configured in pom.xml in subdirectory java-module as follows:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>${version.plugin.codehaus.findbugs}</version>
<configuration>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<xmlOutput>true</xmlOutput>
</configuration>
</plugin>
</plugins>
</reporting>
Despite the configuration being done only for the java-module, FindBugs will always also analyze scala-module.
Add a configuration the scala-module pom.xml that explicitly instructs findbugs to skip the module, i.e.
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</reporting>
Note that Maven often requires you to repeat boilerplate XML for cases like this.
Noahlz's answer did not work for me, but adding the following snippet to the sub-module's POM.xml did the trick.
<properties>
<findbugs.skip>true</findbugs.skip>
</properties>

Resources