PR code coverage with maven and SonarQube 8.4

Hi,

I tried to find the answer on this forum, but no luck so far.
Our setup is:

we have the 8.4 entreprise version.
whenever someone create a PR or merge into our master branch, we use a Jenkins pipeline where the docker sonar scanner (https://github.com/SonarSource/sonar-scanner-cli-docker) is used to scan the project.
I have the following behaviour for different java 8 projects:

when I merge a gradle project (that produce a jacoco.xml file), I get code coverage in SonarQube
when I merge a maven project (that produce a jacoco.xml file with jacoco 0.8.5), I get code coverage in SonarQube
when I create a PR for a gradle project (that produce a jacoco.xml file), I get PR code coverage in SonarQube
when I create a PR for a maven project (that produce a jacoco.xml file with jacoco 0.8.5), I DON’T get PR code coverage in SonarQube
i tried to check any issue with the jacoco.xml file, but didn’t find anything significant.

and AFAIK, the sonar-project.properties is quite standard across all our repo.
Something like

sonar.host.url=https://sonar.mycompany.com
sonar.projectKey=myproject
sonar.projectName=myproject
sonar.sources=src/main
sonar.tests=src/test
sonar.java.binaries=target/classes
sonar.java.libraries=target/*.jar
sonar.coverage.jacoco.xmlReportPaths=target/jacoco-report/jacoco.xml

Does someone has any clue what is wrong? :frowning:

Hi,

Presumably you’re using the Sonar Scanner for Gradle and the Sonar Scanner for Maven for Gradle and Maven projects, respectively. Those scanners read most of their values from the build environment, so there’s little need to pass parameters explicitly and certainly no need to create a sonar-project.properties file; those scanners don’t read it.

Probably your next step in debugging this is to add -Dsonar.scanner.dumpToFile=[file name] to the command line for working and non-working analyses. Then you can compare what values analysis is actually getting and go from there.

 
HTH,
Ann

nice, thanks for the Dsonar.scanner.dumpToFile tip, I will try that, hope I will find something :wink:

1 Like

Just be sure to start that with a ‘-’ i.e. -Dsonar.scanner.dumpToFile. Leave the ‘-’ off and you’ll get an error about tasks not being supported.

 
:wink:
Ann

yes yes! :slight_smile:

Nicolas,
Also check the scanner logs of those builds, with debug enabled. You should see if it’s loading the JaCoCo’s report or not.

Hi found my issue (by using the -X argument).

it is the way Jenkins is cloning the repo
I was using

                checkout scm: [
                    $class           : 'GitSCM',
                    branches         : scm.branches,
@@ -28,7 +31,7 @@ pipeline {
                            [$class: 'CloneOption', noTags: false],
                            [$class: 'LocalBranch', localBranch: "master"]
                    ]
                ]

because we clone the local branch as master, it doesn’t manage to see the difference with … master

Maybe it can help others!

Thanks guys for the quick support/answers

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.