Sonar Plugin configuration to use cobertura - maven

Please let me know how to configure sonar to use cobertura instead of jacoco which is the default.
i have this in my parent pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>1.0</version>
</plugin>
Apart from this i dont know how to add configuration properties.Cobertura setting is there in child poms which will build n show coverage with cobertura locally.
I problem is configuring the right setting in parent pom.and what are the changes i should make in the sonar web interface ->General Settings.
Help Appreciated.Thank you.

There is documentation about the properties. I suspect you want to redefine the sonar.java.coveragePlugin property as a starter.

You'll have to configure that in Sonar directly. Besides, in order to use Cobertura for Java 7 projects you need Cobertura >= 2.0 which was only released a few days ago.
As a sidenote, here a two somewhat older comparisons of the various coverage tools for Sonar:
http://java.dzone.com/articles/code-coverage-tools-comparison
http://www.sonarsource.org/pick-your-code-coverage-tool-in-sonar-2-2/

Related

How can I ignore Annotations when using Maven CPD?

I know there is an option to ignoreAnnotations in the CPD CLI reference guide but I can't seem to get this to work using maven pmd:cpd plugin. When I view the mvn pmd page it doesn't list 'ignoreAnnotations' as a usable parameter but seems like it should support if can do through CLI no??
I tried in pom like this
<configuration>
<ignoreAnnotations>true</ignoreAnnotations>
</configuration>
Thanks
Update, 2019:
maven-pmd-plugin version 3.11.0 added the ignoreAnnotations configuration option.
See plugin documentation: http://maven.apache.org/plugins/maven-pmd-plugin/cpd-mojo.html#ignoreAnnotations

How to publish Scalastyle results in Jenkins Maven job?

We have a Scala project and use Maven and Jenkins for building it. Now we also want to use Scalastyle for static code analysis.
It works fine in the IDE and if I use a Jenkins freestyle job. The output file is created and Jenkins shows a nice graph with the style warnings and errors.
However, if I use a Jenkins Maven job, the "Checkstyle trend" remains empty, although the xml file is there and has the right name (checkstyle-result.xml).
I found this. The discussion there is a bit confusing, but I understood that publishing the Scalastyle results should also work for a Maven job.
Did I get that wrong? Or is there in fact a way to make Jenkins publish the Scalastyle results for my Maven job? Or some kind of workaround? (Apart from using a freestyle job or SBT...)
After trying out some things, I found the solution. All I needed was a Scalastyle entry in the root pom of my multi-module project that looks like this:
<build>
<plugins>
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<version>0.8.0</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/scala</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/scala</testSourceDirectory>
<configLocation>scalastyle_config.xml</configLocation>
<outputFile>${project.basedir}/checkstyle-result.xml</outputFile>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
</plugins>
</build>
The important part here is ${project.basedir}. I tried it before without and it didn't work.
In the project configuration in Jenkins I give the scalastyle:check goal in the section Build -> Goals and options, e.g.
clean install scalastyle:check
Under Build settings I ticked the checkbox Publish Checkstyle analysis results.
Now Jenkins publishes the Scalastyle results. One problem remains, however: Jenkins doesn't seem to pick up my Scalastyle config file (scalastyle_config.xml) but uses the scalastyle-maven-plugin's default rules. At least that's what I suspect, because for the same project I get more Scalastyle warnings in IntelliJ (which uses my custom config file) than in Jenkins...
UPDATE: I was wrong with that. Jenkins does indeed pick up my custom rules. Nevertheless it shows more Scalastyle warnings than IntelliJ does. I'll look into that later.

Why maven-surefire-plugin needs to be defined for the tests to be run

If I call mvn install for example, the test phase being located before in the hierarchy should be executed. However it seems not to be the case.
I actually need to specify it manually: mvn test install in order for my tests to be executed.
OR
Respecifying the surefire plugin in the pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
</plugin>
The test phase is supposed to call the maven-surefire-plugin which is a core plugin.
This behavior doesn't seem consistent to me. Am I missing something ?
EDIT: I am using Maven 3.2.1
The Maven version I am using (3.2.1) embeds the version 2.12.4 of the maven-surefire-plugin.
My project was a study case and had no test classes in it.
The 2.4.2 version of maven-surefire-plugin must fetch by default the Test reports even if no test class is encountered. The 2.12.4 seems not to behave this way.
When I was specifying the maven-surefire-plugin, I was overriding the plugin definition to the version to 2.4.2.
My apologies for having taken your attention for such an edge case and also with a lack of details.

Maven: skip test but still fails on surefire

I dont know if this is a question or suggestion. But I am going to ask it as a question cos may be i am doing something wrong.
My problem was that I wanted to skip tests in maven build, In eclipse plugin I checked the Skip Test option in configuration when running maven. It was still failing on the Test surefire plugin as it couldn't download the version 2.4.3 (even though my previous maven project used a 2.7.2 and it was already there in my repo) So i tried with skipping tests and it still failed.
I configured my POM to use the 2.7.3 plugin of surefire which i already had and it went forward only to say Skipping Tests. Now, my confusion is that when it was already going to SKIP the test part why bother going into the download and confirming if the plugin for surefire is there or not. Just Skip it I say..
well, Is that the normal behavior of maven that when you skip something the plugin is still downloaded as if you are going to use it. Or was I doing it wrongly that made it download it.
May be because there was something new called "Effective POM" and it contained a listing of surefire plugin 2.4.2 in the plugin management area, when i imported my maven project in eclipse using the m2eclipse and i couldnt edit the Effective POM. I had not seen this before in the NetBeans when making the maven project.
In order to work i added an unnecessary surefire plugin entry in my build profile and skipped the tests there as well and added the version that I had in my repo already. I only did this so that my project can be built under eclipse as well. other wise my project works in NetBeans and simple command line without any issues.
Any comments!!
I think maven should be able to see first the SKIP part and then proceed into the usage of the plugin.
Syed..
Based on what you mentioned you didn't understand the difference between using a plugin and configuring the plugin. In this case you are using the plugin (it's in your build area or as you already figured out coming via super-pom). Furthermore you are trying to skip the tests despite the fact that maven-surefire-plugin in version 2.7.3 does not exist.
The configuration parameter skip will not execute the tests as well as not compile them. If you wan't just ignore the tests for a limited time you can use the "skipTest" parameter which in contradiction to skip will continue to compile the tests.
I would recommend to use a pluginManagement section of your project or your parent pom to define the version of the maven-surefire-plugin (which in the meantime exists in version 2.12)...
The following snippet add the pluginManagement part to a pom which controls which version of the maven-surefire plugin will be used.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
..
</build>
After you inserted that into your project pom the output effective pom should give you the version...otherwise you might need to update the project configuration first.
Compiling and running tests is part of the default lifecycle of maven. Since maven uses surefire to do run tests, it needs to download surefire. skipTests is not a maven configuration, but a surefire plugin configuration. The plugin determines that maven needs to skip tests.
As for 2.4.3 of surefire plugin, it is a valid version, but will work with 2.0.6 version of maven. Most likely you are using a newer maven, but, for some reason have the super pom of the older maven version on your system.
skipTest doesn't tell maven to skip the test lifecycle, it tells the surefire plugin not to run them. The plugin is still part of the lifecycle (it just does nothing when it's called). Hence your error.
If you want to NOT have surefire at all, you need to define your own packaging (since surefire is part of the standard jar packaging lifecycle) - which is a lot more work than just choosing a version of surefire that works for you (add a section with the right in your section).

Maven's site generation is not working

Anyone not getting mvn site output? I was getting site output on my Macbook pro and I have deployed the site too. But tonight nothing works:
[INFO] --- maven-site-plugin:2.0.1:site (default-cli) # svs-utility ---
No reports or HTML generated
I think that with Raghuram advice you've already figured out, however, I saw this question today and I had the same problem. I'm learning Maven and I thought to document my steps here since it may be useful to someone else. I'm running Maven 3.0.1 and it was using version 2.0.1 of the plugin which doesn't work.
I found another question on stackoverflow explaining how to upgrade a Maven plugin.
As #andri said:
The default plugin versions are
inherited from the Super POM, and you
can check them with mvn
help:effective-pom.
I checked and it was indeed using 2.0.1 - I searched on http://search.maven.org/ for the latest version of site plugin and at the time of writing is 3.0-beta-3 (UPDATE 3.0 is out, I've updated the code below).
However #andri answer doesn't report the correct structure as in the super POM, while #Brian Fox answer does. Combining the two answers and the info found in the Maven repo, I added the following to my pom.xml
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
With this change "mvn site" now works.
Now someone might ask, why Maven 3 ships with a plugin that doesn't work. It turns out that Brian Fox, a Maven developer has decided to lock down plugins to version 2. In general this seems a good idea for stability, however since backward compatibility is not honored, it becomes a very bad idea in this specific case. A plugin in super pom should work out of the box for the version it's packaged for. Either backward compatibility should be provided or it should be updated to the new version.
Maybe it will be fixed later, in the meantime the above workaround works. It's also a good idea to lock down the version of the plugin to the specific project.
Are you using maven 3? If so, you need to use the 3.x version of the site plugin

Resources