SonarQube: 8.2.0.32929
sonar-scanner: 3.0.3.778
jacoco: 0.8.4
jdk: 1.8
mvn: 3.6.3
What are you trying to achieve
I am trying to achieve code coverage by using sonar-scanner but I am getting code coverage 0 in sonarqube dashboard.
What have you tried so far to achieve this
I configured the multi-module java project using https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule
and created sonar-project.properties file in base directory with below configuration
sonar.projectKey=org.sonarqube.sonarscanner-maven-aggregate
sonar.projectName=Sonar Scanner Maven Aggregate
sonar.projectVersion=1.0
sonar.language=java
sonar.java.binaries=.
If I use mvn sonar:sonar it works. but with sonar-scanner it is not working.
It works fine with sonarqube 7.8.
Any insight would be appreciated.
I fixed this issue.
while running sonar-scanner command, I added the xmlReportPaths as a define property like sonar-scanner -Dsonar.coverage.jacoco.xmlReportPaths=tests/target/site/jacoco-aggregate/jacoco.xml,../tests/target/site/jacoco-aggregate/jacoco.xml
If your projects are set up as multi-module, you will have to feed the coverage report from each module to the last module that will run as part of the build (probably integration tests modules)
https://community.sonarsource.com/t/coverage-test-data-importing-jacoco-coverage-report-in-xml-format/12151
https://community.sonarsource.com/t/in-sonarqube-8-2-code-coverage-is-always-showing-0/21666
https://docs.sonarqube.org/latest/analysis/coverage/
https://stackoverflow.com/a/15535970
Following the steps mentioned in this example project by Sonar team helped me
https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven/maven-multimodule
As you already followed these steps, one thing I was missing was the aggregated report was not generated in the last module and I was doing it in one module before that which was our integration test module. But there was one more deployment module in our case
Related
is there any reason for a jacoco coverage report to produce different results when running it in a CI environment?
I have the following situation after migrating to Java 17. when I run ./gradlew clean build the report is generated and the jacocoTestCoverageVerification doesnt fail.
But when the same command is executed in a github runner I have a very different result, the coverage report is also created with different coverage values and some classes just fail the coverage verification.
Unfortunately, I cannot provide code snippets but I already tried this:
Run the github runner on my machine, with the same jdk and it produces a different result if I just run the build in the command line :(
add jvmargs noverify for tests tasks
run the github action in a container instead of a self-hosted, same result
other devs have also built the project on different machines without error
run the same build command of the ci
So it seems that something in a github action env produces this behavior.
versions:
jacoco plugin: 0.8.7
gradle 7.3
java 17
The problem here was lombok config files. It turns out that the new version of lombok plugin compatible with java 17 and Gradle 7.3 does not generate the lombok.config files anymore.
In the previous version, these files were generated by io.freefair.lombok plugin, and we had them in .gitignore. Because of that, a local build worked just fine, since the files were still there.
I realized this by looking at the generated reports and I noticed that lombok classes were being analyzed only by the CI.
In other cases, a similar problem could be related to this:
https://www.eclemma.org/jacoco/trunk/doc/classids.html
I have a ivy project setup in jenkins, on which I like to run sonarqube analysis.
Unfortunately it is not possible (it seems) to add the sonarqube analysis on the project itself, but I need to create a mirror project (free-style) with sonarqube scanner as only build step.
I also need to set then the basedir not to the mirror project, but to the original one.
All this is a bit unfortunate and I was wondering whether there is another option to run a sonar analysis on an ivy project in jenkins ?
I have Jenkins 2.7.4, Sonarqube plugin 2.4.4
I could achieve my goal with using the PostBuildAction plugin.
This allowed to add the sonarqube-scanner job to be added at the end of the run.
How can see unit test integration result of non-maven java project in sonar. I have the latest version of Sonar installed and have latest java plugin. I think this java plugin comes along with jacaco and surefire. I used sonar-runner to analyse my project.
How can I run jacoco with my non maven java project and integrate the result with sonar.
You can check the following example to see how to get coverage result with JaCoCo and SonaQube runner: https://github.com/bellingard/multi-language-test
More specifically, look into the sonar-project.properties file and this section:
# For Java
sonar.junit.reportsPath=reports/java/surefire-reports
sonar.jacoco.reportPath=reports/java/jacoco.exec
sonar.binaries=target/classes
I have a Scala project built with SBT. I use Jenkins to do my build, and include the following as a build target:
scoverage:test
This gets me very nice coverage reports for my Scala sources using the Cobertura plugin for Jenkins.
My project has Java files as well, however, and I get no coverage for them. If this were Maven, I'd know what to do. But being SBT, I'm a bit unclear on how I can get coverage for the Java sources and then ensure that Jenkins sees the output and displays it as well.
I do know that the Java tests run using "sbt test" so that's not an issue.
Is this even possible?
I am successfully running Cucumber test on my java/maven eclipse project. But when I add my project do Jenkins I always get the following error "cucumber.runtime.CucumberException: No features found at []".
I read in this thread Setting cucumber-jvm options in Maven from the command line that:
...tests are running in separate JVM, so you need to specify that system property in the test plugin configuration (i.e. surefire or failsafe plugin config in your pom.xml)
But I am not quite sure how to do this. Can anyone help me?
PS: I am using "cucumber-java" and "cucumber-junit" dependencies.
If you're using surefire, the plugin documentation page http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html shows few options you can try to set system properties
For example you can try the systemPropertyVariables plugin settings
do you see the feature files in your target folder on your Jenkins slave ? maybe your *.feature files get excluded because of an incorrect config of your resources exclusion/inclusion in Maven ?