What is the purpose of sonar-maven3-plugin? - maven

I want to analyze a Maven 3 project. I found the following plugins:
org.codehaus.mojo:sonar-maven-plugin:2.0
org.codehaus.sonar:sonar-maven-plugin:3.6.2
org.codehaus.sonar:sonar-maven3-plugin:3.6.2
So I can run Sonar analysis with 3 ways:
mvn org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (or simply mvn sonar:sonar since the package is org.codehaus.mojo)
or
mvn org.codehaus.sonar:sonar-maven-plugin:3.6.2:sonar
or
mvn org.codehaus.sonar:sonar-maven3-plugin:3.6.2:sonar
What is the most appropriate way for me?

Regarding the different groupIDs of the plugins you mentioned, this is explained here:
What is the difference between org.codehaus.mojo:sonar-maven-plugin and org.codehaus.sonar:sonar-maven-plugin?

The documentation is clear about that: you just have to execute mvn sonar:sonar to run your analysis, no need to worry about anything else - SonarQube handles that for you.

Related

How to completely skip unit tests and integration tests during maven release prepare and perform with maven release plugin

I have set up some automation to perform maven semantic versioining using maven release plugin. As such i am using the below :-
mvn -B clean release:clean -DpreparationGoals=clean release:prepare -Darguments="-DskipTests" -Darguments="-DskipITs" -Darguments="-Dmaven.javadoc.skip=true" release:perform -Dusername=$GIT_USERNAME -Dpassword=$GIT_PASSWORD
Everything works great except for the fact that during perform phase, i still see the TESTS being executed in our jenkins logs.
I am wondering what would be the best way to skip any kind of tests during this maven release prepare and perform without having to make any changes in existing pom.xml as i would like to enforce that through maven arguments passed as CLI arguments so that we don't have to update 1000 of poms using this automation
Any help or suggestions here would be greatly appreciated as always.
You can use the arguments property to do this. Quoting can be very important.
Example:
mvn release:prepare ... -Darguments="-Dmaven.test.skip=true -DsomethingElse=whatever"
Here, I pass the maven.test.skip property (defined by the maven-surefire-plugin's test goal) through to the execution of mvn run by the prepare goal of the maven-release-plugin.

Why should run first mvn clean clover2:setup install clover2:clover, then: mvn sonar:sonar

Based on the question Sonar + Clover only runs on src-instrumented, it is suggested using first mvn clean clover2:setup install clover2:clover, then: mvn sonar:sonar.
Just wonder why we cannot use mvn clean clover2:setup install clover2:clover sonar:sonar?
In the past it was the recommended way to run goal sonar:sonar alone. This is no more the case since SonarQube Scanner for Maven stopped trying to run unit tests + collect coverage for you by forking a new Maven lifecycle.
General advice is now to run goals in a single command. For example mvn clean package sonar:sonar
In the case of Clover the clover:setup goal will alter the Maven Model to make all other plugins (like surefire) use instrumented classes instead of original source code. This is indeed a problem because it will prevent SonarQube to match class files. So in your case you should either stick with two separate goals, or manually configure sonar.sources to refer to original source code.
Compared the maven logs and found the possible reason:
The "mvn clean clover2:setup install clover2:clover sonar:sonar" seems having issue to find the Source dirs. The log shows it uses ${project}\target\clover\src-instrumented and ${project}\target\generated-sources\annotations as the source dirs.
If explicitly specify src/main/java, then this single command works well. The only tricky thing is why running the goals separately doesn't need to specify sonar.sources but the plugin can still find the right folder for source dirs.

How to run only a single Scalatest (via wildcardSuites) in Spark when including Maven profiles

I have the following command line to run a Spark scalatest via maven:
mvn -pl mllib -Pyarn -Phadoop-2.6 -Dhadoop2.7.1
-Dscala-2.11 '-D!scala-2.10' -Dmaven.javoc.skip=true
-DmembersOnlySuites=org.apache.spark.ml.feature.BinarizerSuite test
Let us break it down a bit:
Select only the mllib module:
-pl mllib
Set various profiles and scala settings:
-Pyarn -Phadoop-2.6 -Dhadoop2.7.1 -Dscala-2.11 '-D!scala-2.10' -Dmaven.javoc.skip=true
Note: those profiles and settings are required for getting the right compilation options for our environment. They have been verified many times for packaging.
Choose the BinarizerSuite only:
-DwilcardSuites=org.apache.spark.ml.feature.BinarizerSuite test
The result is close to what I hope for - except the mllib java testcases are being run.
I have used the
mvn -DwildcardSuites=org.apache.spark.ml.feature.BinarizerSuite test
and that DOES do the right thing: only the one Suite is tested. So it seems the maven command line parser is not being fed the expected order of options. But I have tried all the different permutations of ordering them..
Sean Owen on the Spark mailing list provided the answer: I was missing the following setting:
-Dtest=None
That setting turns off the Java tests.

sonar skipping all modules except root one

I'm trying to run sonar on entire project using maven, but for some reason it skips submodules and analyse only root module. Is there any explanation of such a strange behaviour?
Any help is greatly appreciated!
Here is maven final output:
ADDITION
mvn clean install doesn't skip anything, but mvn sonar:sonar do.
The SonarQube Maven Plugin is an aggregator plugin. It's executed only on the root module. That's the reason why Maven flags sub-modules as SKIPPED, even if they are correctly analysed.
I do not find full description, but have youtried sonar.includedModules=rootModule?
Source

Executing a specific Maven phase

Is there any way to execute a specific phase in a maven build. For example, if I only want to run those plug-ins that execute in the pre-integration-phase, does Maven provide a means to do that?
e.g.
mvn pre-integration-phase
You can't call the life-cycle-phase itself but you can call the goals of the plugins which are bound to the life-cycle-phases.
mvn compile:testCompile
mvn failsafe:integration-test
but usually this shouldn't be needed...
No. You'd have to run the plugins manually.

Resources