SonarQube doesn't display my aggregate coverage report

Hi all,
We have Sonar enterprise version installed in our company. We have been playing with a simple multi module java project and obtained an aggregate jacoco.xml report which contains all the coverage view in the project. The problem is that SonarQube is unable to display it in the GUI (it’s all the time 0 coevarge)
The skeleton of the project looks like this

parent pom.xml 
        ... contains  ...
                         <modules>
                           <module>processing</module>
                           <module>reports</module>
                          <module>aggregator</module>
                         </modules>
                         ...
                               <profile>
            <id>integration</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>3.1.2</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <includes>
                                <include>**/*IT.java</include>
                            </includes>
                        </configuration>

                    </plugin>
                </plugins>
            </build>
        </profile>

two submodules:  
             report and processing which contains BOTH
  <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.11</version>
                <configuration>
                    <!-- Rest of your configuration, if any -->
                    <formats>XML</formats>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
and an aggregator submodule like:
      contains the dependencies for both sub modules: report and processing
      <dependencies>
        <dependency>
            <groupId>com.mercuria.multiprj</groupId>
            <artifactId>reports</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.mercuria.multiprj</groupId>
            <artifactId>processing</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

and 
 <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.11</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <configuration>
                            <dataFileIncludes>
                                <dataFileInclude>**/jacoco.exec</dataFileInclude>
                            </dataFileIncludes>
                            <outputDirectory>
                                ${project.reporting.outputDirectory}/jacoco-aggregate
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

The jacoco.xml file looks pretty good, also we obtained the html report which is browsable and contains accurate report, but somehow the sonarqube is not able to interpret it.

We use a stage in gitlab with sonar-scanner and i’m able to see
this:
07:30:42.768 DEBUG: Reading report ‘/builds/development/finance/sandbox/giant-multimodules/target/site/jacoco-aggregate/jacoco.xml’

80907:30:42.781 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=16ms

But no report is shown in the SOnarQube page :frowning:
Can you help us with some hints ?

Thanks

Hi,

I’m not seeing the property for the aggregated report that’s described in the docs. Can you give that a try?

 
Ann

Hi Ann,
Thank you for your fast response, and sorry for my late response ( i was in a short holiday all these days). As I mentioned the report is generated locally, is also loaded by sonarQube, but nothing appear.
In the code above listed, I added also the aggregator report, and is almost the same as it is in the docs:

 <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.11</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>report-aggregate</goal>
                        </goals>
                        <configuration>
                            <dataFileIncludes>
                                <dataFileInclude>**/jacoco.exec</dataFileInclude>
                            </dataFileIncludes>
                            <outputDirectory>
                                ${project.reporting.outputDirectory}/jacoco-aggregate
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Hi,

What I was looking for is the property that tells analysis where to find your aggregated report:

<properties>/
  <sonar.coverage.jacoco.xmlReportPaths>
    ${project.basedir}/report-aggregate/target/site/
      jacoco-aggregate/jacoco.xml
  </sonar.coverage.jacoco.xmlReportPaths>
</properties>

 
Ann

Hi,

We have this property set on all three submodules: aggregator, report and processing

      <sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/aggregator/target/site/jacoco-aggregate/jacoco.xml
</sonar.coverage.jacoco.xmlReportPaths>

Now , maybe the problem is in the following gitlab steps listed below. I’m doing a hack, somehow on the app build step i generate the reports in the aggregator submodule and copied into a folder called artifacts (which is preserved during stages) and on the sonar-check step I copied the content of it, back to target folder of the root project.

app-build:
  stage: app-build
  image: $MAVEN_IMAGE
  extends:
    - .sentry-release
  before_script:
    - mkdir -p artifacts
  script:
    - set -o xtrace
    - mkdir -p $CI_PROJECT_DIR/.m2/repository
    - mvn -B versions:set -DnewVersion=${CI_COMMIT_TAG:-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA}
    - mvn -B -Dsentry.release=$SENTRY_RELEASE verify
    - cp -R aggregator/target artifacts
  artifacts:
    expire_in: 1 day
    paths:
      - artifacts


maven-integrate:
  stage: integrate
  image: $MAVEN_IMAGE
  artifacts:
    expire_in: 4 hrs
    when: always
    reports:
      junit:
        - reports/target/failsafe-reports/TEST-*.xml
        - reports/target/surefire-reports/TEST-*.xml
        - processing/target/failsafe-reports/TEST-*.xml
        - processing/target/surefire-reports/TEST-*.xml
        - aggregator/target/site/jacoco-aggregate/jacoco.xml
  before_script:
    - set -o xtrace
    - mvn -B versions:set -DnewVersion=${CI_COMMIT_TAG:-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA}
  script:
    - mvn -B clean verify -P integration

sonarqube-check:
  image:
    name: sonarsource/sonar-scanner-cli:latest
  stage: .post
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - sonar-scanner -Droject.settpings=./sonar-project.properties


BTW my sonar-project.properties looks like
sonar.projectKey=${env.SONAR_PROJECT_KEY}
sonar.host.url=${env.SONAR_HOST_URL}
sonar.verbose=true
sonar.java.binaries=${env.CI_PROJECT_DIR}/target
sonar.java.sources=${env.CI_PROJECT_DIR}/reports,${env.CI_PROJECT_DIR}/processing
sonar.coverage.jacoco.xmlReportPaths=${env.CI_PROJECT_DIR}/target/site/jacoco-aggregate/jacoco.xml
sonar.exclusions=src//test//*

Eddie

Hi,

Thanks for sharing this. Can you double-check that the file paths in the report match the file paths analysis is seeing? This (admitted) hack makes me wonder if pathing isn’t the problem.

 
Ann

Hi Ann,
For the sake of simplicity I’ve added the skeleton of the project here GitHub - eddieserban123/multiprj
As you see there is a typical parent project with two submodules: report and processing. The aggregator role is to aggregate the jacoco report. There is a hack in the gitlab ci file here: https://github.com/eddieserban123/multiprj/blob/main/.gitlab-ci.yml

Please have a look and tell me if you find smth suspicious.

As i mention the final report jacoco.xml looks good and is loaded by sonarqube.

Thank you vey much!

Hi,

Thanks for the sample project. I’m not a Mavenista, so there are some things I’m not sure about, but you say you’re getting the report (locally) that you expect. So we’ll set those aside.

Going back to this:

You move the aggregated report file around before anlaysis and in the end, put it in the project root target directory.

But analysis is looking for it in

        <sonar.coverage.jacoco.xmlReportPaths>
            ${project.basedir}/aggregator/target/site/jacoco-aggregate/jacoco.xml
        </sonar.coverage.jacoco.xmlReportPaths>

Can you share your share your analysis log?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Ann

Hi,
Lemma explain how i see the flow:

  1. All the modules (including the aggregate) are instructed to aggregate the report in the aggregate/target…folder
  2. the target folder in copied in a permanent folder named artifacts
  3. before sonnar-scanner invocation the artifacts folder is moved into the root target folder
  4. sonnar-scanner is invoked with sonar-scanner -Droject.settpings=./sonar-project.properties
  5. the aggregate report is loaded : this is the output
19:02:14.728 DEBUG: Reading report '/builds/development/finance/sandbox/giant-multimodules/target/site/jacoco-aggregate/jacoco.xml'

As a side note:
the content of sonar-project.properties is here

Hi,

This is a Maven project. You should be using the SonarScanner for Maven.

 
Ann

Hi,
Well we have a problem and we were forced to use sonnar scanner
( which is basically the same as being invoked from maven sonar plugin) because the initial java multi module project is written in an old java 8 and latest sonarqube maven plugin cannot be invoked for java 8. But it should be perfect fine, the same sonar scanner command is used for other different java single module projects(in company) and is working fine. So it should be ok.

Hi,

You can certainly build with Java 8 and then analyze with Java 17. Or you can set your -target 1.8 and do it all with Java 17.

 
Ann

Hi,
Well the problem is that everything is dockerize and we don’t have an image with two java versions. However i’ve uploaded the content of the aggregated report (jacoco.xml) and it looks good IMO.
jacoco.zip (1.1 KB)

Hi,

So you’re running the SonarScanner CLI with Java 8? That means it’s pretty out of date at this point. You need to figure out how to run a current, supported scanner version, and it might as well be the SonarScanner for Maven.

 
Ann

Hi,
We are pulling sonarcli from https://hub.docker.com/r/sonarsource/sonar-scanner-cli (which contains SONAR_SCANNER_VERSION=5.0.1.3006 and java 17) and we just ran it as:
sonar-scanner -Droject.settpings=./sonar-project.properties
Basically we give the location of the jacoco.xml from the aggregated report
The content of sonar-project.properties is:

sonar.projectKey=${env.SONAR_PROJECT_KEY}
sonar.host.url=${env.SONAR_HOST_URL}
sonar.verbose=true
sonar.java.binaries=${env.CI_PROJECT_DIR}/target
sonar.java.sources=${env.CI_PROJECT_DIR}/reports,${env.CI_PROJECT_DIR}/processing
sonar.coverage.jacoco.xmlReportPaths=${env.CI_PROJECT_DIR}/target/site/jacoco-aggregate/jacoco.xml
sonar.exclusions=src/**/test/**/*

Hi,

Can you try this with SonarScanner for Maven?

 
Ann