Using SonarQube 6.3, sonar-maven-plugin 3.3.0.660, Java 8, on a multi-module Maven project.
On the source files, code coverage (with JaCoCo) is working well, as are the analysis plugins, duplication detection, test executions and duration etc. But, we have no metrics for test files. The files are being loaded into SonarQube, but Lines of Code and Duplications are blank (as is Coverage but that one makes sense), while Bugs, Vulnerabilities, and Code Smells are all 0. We may have something configured incorrectly but I can't figure out what.
Example: one module contains Java and XML source and test files. The sonar properties in the POM are:
<sonar.sources>.</sonar.sources>
<sonar.inclusions>src/main/**/*,src/app/**/*,**/*.xml,**/*.properties,**/*.json</sonar.inclusions>
<sonar.tests>.</sonar.tests>
<sonar.test.inclusions>src/test/**/*,e2e/**/*</sonar.test.inclusions>
In SonarQube --> Administration --> Analysis Scope, we have Import Unknown Files enabled. We also have the property sonar.global.exclusions set to target/**/*
When running an analysis with the Maven plugin, we see messages like this in logs:
[INFO] 13:01:35.726 Base dir: /JENKINS_WS/project/module
[INFO] 13:01:35.726 Working dir: /JENKINS_WS/project/module/target/sonar
[INFO] 13:01:35.726 Source paths: .
[INFO] 13:01:35.726 Test paths: .
[INFO] 13:01:35.726 Source encoding: UTF-8, default locale: en_US
[INFO] 13:01:35.726 Index files
[INFO] 13:01:35.726 Included sources:
[INFO] 13:01:35.726 src/main/**/*
[INFO] 13:01:35.726 src/app/**/*
[INFO] 13:01:35.726 **/*.xml
[INFO] 13:01:35.726 **/*.properties
[INFO] 13:01:35.727 **/*.json
[INFO] 13:01:35.727 Excluded sources:
[INFO] 13:01:35.727 target/**/*
[INFO] 13:01:35.727 src/test/**/*
[INFO] 13:01:35.727 e2e/**/*
[INFO] 13:01:35.727 Included tests:
[INFO] 13:01:35.727 src/test/**/*
[INFO] 13:01:35.727 e2e/**/*
...
It appears that files in the test directories are being indexed properly:
[DEBUG] 13:01:35.778 'src/test/resources/log4j.xml' indexed as test with language 'xml'
[DEBUG] 13:01:35.779 'src/test/resources/appContext-test.xml' indexed as test with language 'xml'
[DEBUG] 13:01:35.779 'src/test/java/com/company/module/EnvEchoTest.java' indexed as test with language 'java'
And the Java scanner reports that the single test file was analyzed too:
[INFO] 13:01:38.520 Java Test Files AST scan
[INFO] 13:01:38.520 1 source files to be analyzed
[DEBUG] 13:01:38.521 'src/test/java/com/company/module/EnvEchoTest.java' generated metadata as test with charset 'UTF-8'
[DEBUG] 13:01:38.529 ----- Classpath analyzed by Squid:
[DEBUG] 13:01:38.529 /JENKINS_WS/project/module/target/test-classes
[DEBUG] 13:01:38.529 /JENKINS_WS/project/module/target/classes
... snip printing all the jar file debug msgs ....
[INFO] 13:01:38.567 1/1 source files have been analyzed
[INFO] 13:01:38.567 Java Test Files AST scan (done) | time=47ms
But the metrics are not populated in SonarQube. Can anyone provide pointers?
All is well. Or at least working as designed.
SonarQube is designed to report on the quality of your code, and tests aren't really considered to be code. They're... supporting files.
That said, there is a set of rules written specifically to examine the quality of your tests as tests. If included in your profile, they might raise issues on your tests. But so-called normal rules won't be run against tests, and metrics will not be calculated.
If you really want those things, you'll need to set up a separate, second analysis of your project, where the sonar.sources property points to the tests directory.
Related
I am having a problem regarding aggregating the data of a multi-module maven project in a single store directory using -Djqassistant.useExecutionRootAsProjectRoot=true.
Here is how my project is structured
root-project [NO PARENT]
----/project-A [PARENT company-parent-pom-A]
----/project-B [PARENT company-parent-pom-B]
I am running the following on the root project
mvn clean install -DskipTests=true com.buschmais.jqassistant:jqassistant-maven-plugin:1.2.0:scan -Djqassistant.useExecutionRootAsProjectRoot=true
But it shows following error.
Failed to execute goal com.buschmais.jqassistant:jqassistant-maven-plugin:1.2.0:scan (default-cli) on project root-project: Cannot re-use store instance from reactor. Either declare the plugin as extension or execute Maven using the property -Djqassistant.store.lifecycle=MODULE on the command line.
So I add -Djqassistant.store.lifecycle=MODULE and run the following
mvn clean install -DskipTests=true com.buschmais.jqassistant:jqassistant-maven-plugin:1.2.0:scan -Djqassistant.useExecutionRootAsProjectRoot=true -Djqassistant.store.lifecycle=MODULE
Now the build succeeds. But while scanning the root-project in the end the plugin resets the store directory. So all the data collected before gets removed. Is this an issue of jqa-maven-plugin or am I doing something wrong?
19984 [INFO] --- jqassistant-maven-plugin:1.2.0:scan (default-cli) # project-B ---
22034 [INFO] Loaded jQAssistant plugins [Common, Core Analysis, JUnit, Java, Maven 3, XML].
22082 [INFO] Opening store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
24227 [INFO] Resetting store.
27464 [INFO] Reset finished.
28887 [INFO] Entering /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/classes
29861 [INFO] Leaving /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/classes (183 entries, 972 ms)
29864 [INFO] Entering /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/test-classes
29874 [INFO] Leaving /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-B/target/test-classes (12 entries, 10 ms)
30823 [INFO] Closing store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
...
124415 [INFO] --- jqassistant-maven-plugin:1.2.0:scan (default-cli) # project-A ---
124423 [INFO] Opening store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
124971 [INFO] Entering /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-A/target/classes
124973 [INFO] Leaving /home/mehedi/Develop/WorkSpace/jqa-projects/test-project/project-A/target/classes (2 entries, 1 ms)
125222 [INFO] Closing store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
...
138156 [INFO] --- jqassistant-maven-plugin:1.2.0:scan (default-cli) # root-project ---
139411 [INFO] Loaded jQAssistant plugins [Common, Core Analysis, JUnit, Java, Maven 3, XML].
139448 [INFO] Opening store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
140780 [INFO] Resetting store.
146562 [INFO] Reset finished.
147842 [INFO] Closing store in directory '/home/mehedi/Develop/WorkSpace/jqa-projects/test-project/target/jqassistant/store'.
The setup you're describing should be working so likely you found a bug. Can you report this please on https://github.com/buschmais/jqa-maven-plugin?
Is the maven surefire plugin needed to run unit tests when using the mvn clean test command?
I read the documentation and know it says that:
The Surefire Plugin is used during the test phase of the build
lifecycle to execute the unit tests of an application. It generates
reports in two different file formats:
Plain text files (.txt) XML files (.xml) By default, these files are
generated at ${basedir}/target/surefire-reports.
However, I ran the tests without using the surefire plugin and they all passed.
no not needed but it is used by maven per default. if you have a better plugin you can change it. but i would prefer the defaults.
the maven-surfire-plugin is bound to the test phase of the default lifecycle. the maven-surfire-plugins runs all Tests matches the filename pattern Test*.java, *Test.java und *TestCase.java reside in the directory src/test/java.
for more information have a look at http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html
you can verify this on the console output... here is the tailed output of mvn test...:
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # rechnungsverwaltung ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # rechnungsverwaltung ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.447 s
[INFO] Finished at: 2015-10-17T22:36:59+02:00
[INFO] Final Memory: 18M/304M
[INFO] ------------------------------------------------------------------------
Hava a look at the line. there you can see that the maven-surefire-plugin is used
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) #
I am trying to run a sonar maven analysis on my multilanguage project which contains many languages like *.java, *.groovy, *.js etc. I have installed all the languages plugin in my sonar and configured my pom sonar.sources parameter as src/main,src/test but still it picks up only java files. In the console output.
I get the following lines in the console indicating that it only scans the folders with pattern src/main/java and src/test/java
[INFO] [05:13:57.140] ------------- Scan myapp
[INFO] [05:13:57.140] Load module settings
[INFO] [05:13:57.187] Initializer FindbugsMavenInitializer
[INFO] [05:13:57.187] Initializer FindbugsMavenInitializer (done) | time=0ms
[INFO] [05:13:57.187] Base dir: C:\myapp
[INFO] [05:13:57.187] Working dir: C:\myapp\target\sonar
[INFO] [05:13:57.187] Source paths: pom.xml, src/main/java
[INFO] [05:13:57.187] Test paths: src/test/java
I am currently using SonarQube 5.1, Java 7u80
Note: If analysis is done using Sonar Runner, It scans all the files.
Since SonarQube 4.2, it is possible to run an analysis on a multi-language project. To do so, the sonar.language property just has to be removed. Conversely, if for some reason you want to perform a single language-only analysis, make sure sonar.language is specified.
By default the sonar.sources property is set to the value of the Maven sourceDirectory property (by default it is src/main/java) plus pom.xml (and also src/main/webapp is automatically added for war modules). Therefore, for a multi-language project, the property usually has to be overridden to: sonar.sources=src/main,pom.xml.
Since it was a multi module project, I had to include the properties sonar.sources and sonar.tests in the parent module's pom.xml file.
<properties>
<sonar.sources>pom.xml,src/main,src/test</sonar.sources>
<sonar.tests></sonar.tests>
</properties>
sonar.tests parameter is empty since it is incompatible with Maven.
I have a Jenkins+Nexus installation, and some project there that are automated.
Jenkins deploy the sources and javadocs to nexus in the deploy phase (I am using Maven Release) -- Javadoc could be ok but I don't want to have any sources in Nexus.
I was searching and googling and I don't know how to skip this step.
Thanks a lot
Output from jenkins
[INFO] [INFO]
[INFO] [INFO] --- maven-install-plugin:2.3.1:install (default-install) # projectA ---
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/target/projectA-1227.jar to .../projectA-1227.jar
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/pom.xml to .../projectA-1227.pom
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/target/projectA-1227-sources.jar to .../projectA-1227-sources.jar
[INFO] [INFO] Installing /var/lib/jenkins/jobs/MyBuild/workspace/target/checkout/MyProject/projectA/target/projectA-1227-javadoc.jar to .../projectA-1227-javadoc.jar
[INFO] [INFO]
Try adding : -Darguments="-Dsource.skip=true -Dmaven.javadoc.skip=true"
to your maven release plugin config (Jenkins > your build configuration > Maven release build > Release goals and options
By default this actually does not happen automatically. Most likely you have configured a release profile somewhere in your pom hierarchy that adds the Maven Source Plugin execution.
You could remove that if you never want to use it or otherwise change the release plugin config to use a different profile or skip source creation or invoke the build with parameters to skip as Guilame has answered
I followed the instructions to the letter in this blog post by Sonatype on writing a Maven plugin in Ruby.
When I try running mvn install (Maven 3.0.4), the build is successful, but maven-plugin-plugin cannot find any mojo descriptors:
[INFO] ------------------------------------------------------------------------
[INFO] Building Example Ruby Mojo - firstruby-maven-plugin 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.jruby:jruby:jar:0.9.9 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-plugin-plugin:2.4:descriptor (default-descriptor) # firstruby-maven-plugin ---
[INFO] Using 3 extractors.
[INFO] Applying extractor for language: java
[INFO] Extractor for language: java found 0 mojo descriptors.
[INFO] Applying extractor for language: jruby
[INFO] Extractor for language: jruby found 0 mojo descriptors.
[INFO] Applying extractor for language: bsh
[INFO] Extractor for language: bsh found 0 mojo descriptors.
If I try bumping maven-plugin-plugin version to anything higher than 2.4, the build fails with this error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:2.5:descriptor (default-descriptor) on project firstruby-maven-plugin: The API of the mojo scanner is not compatible with this plugin version. Please check the plugin dependencies configured in the POM and ensure the versions match. org.apache.maven.tools.plugin.scanner.MojoScanner.populatePluginDescriptor(Lorg/apache/maven/tools/plugin/PluginToolsRequest;)V -> [Help 1]
Here's the output of tree to show that the directory structure is OK:
firstruby-maven-plugin
├── pom.xml
└── src
└── main
└── scripts
└── echo.rb
3 directories, 2 files
Any idea why it's not working?
The Codehaus jruby-maven-plugin seems to have been abandoned 5 years ago. If you're using Maven3, you can try using Maven2 but I'd look at https://github.com/torquebox/jruby-maven-plugins