New Code coverage is 0 after upgrade from 8.9 to 9.9

Make sure to tell us:

  • Upgraded from 8.9.10 LTS to 9.9 LTS Developer Edition.
  • Ubunu, Java 17, postgres
  • SonarScanner version : — sonar-maven-plugin:3.4.1.1168:sonar

maven code compile is done using jdk8 but running maven sonarscan using jdk11. Coverage was 60% before upgrade but after upgrade I get 0% code coverage and quality gate fails.

Here is the pom template. I do not see any jacoco reference in our pom file. So I am assuming surefire plugin or failsafe plugin is used for running tests.

<profile>
  <id>k8s-integration-tests</id>
  <activation>
    <activeByDefault>false</activeByDefault>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skipTests>true</skipTests>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <parallel>classes</parallel>
          <threadCount>10</threadCount>
          <suiteXmlFiles>
            <suiteXmlFile>src/test/resources/testng.k8s.xml</suiteXmlFile>
          </suiteXmlFiles>
          <skipITs>false</skipITs>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

Commands used as part of our build in GitlabCI.

  • mvn -q -B clean install -DskipTests -Dmaven.javadoc.skip=true
  • mvn -Dmaven.javadoc.skip=true -Pcoverage verify -DskipITs
  • apk add openjdk11; mvn -T 1C sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_USER_KEY -Dsonar.java.binaries=target

Note: After SonarQube Upgrade to 9.9 sonarscans started failing so I had to install jdk11 to make it work.

Hi,

It’s striking to me that your first command includes -DskipTests and your second command includes -DskipITs.

I suppose the -Pcoverage part is supposed to run the unit tests and generate the coverage report?

Can you verify that a coverage report is indeed being created? And being passed in to analysis? Presumably via sonar.coverage.jacoco.xmlReportPaths?

If so, what does your analysis log say about it?

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

Thanks for your response. I am seeing this error.

[WARNING] Some problems were encountered while building the effective model for com.xyz.-test:jar:2.44.0-SNAPSHOT

[WARNING] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun.java:tools:jar refers to a non-existing file /usr/lib/jvm/java-11-openjdk/../lib/tools.jar. Please verify that you run Maven using a JDK and not just a JRE. @ net.openhft:third-party-bom:3.6.2, /root/.m2/repository/net/openhft/third-party-bom/3.6.2/third-party-bom-3.6.2.pom, line 333, column 29

[WARNING] Some problems were encountered while building the effective model for com.xyz.xxyz:xxyz-test-smart:jar:2.44.0-SNAPSHOT

[WARNING] 'dependencyManagement.dependencies.dependency.systemPath' for com.sun.java:tools:jar refers to a non-existing file /usr/lib/jvm/java-11-openjdk/../lib/tools.jar. Please verify that you run Maven using a JDK and not just a JRE. @ net.openhft:third-party-bom:3.6.2, /root/.m2/repository/net/openhft/third-party-bom/3.6.2/third-party-bom-3.6.2.pom, line 333, column 29

Looks like my project has some dependency with jdk8 and here is the reference to the thirdparty pom file file which we do not have control.

.m2/repository/net/openhft/third-party-bom/3.6.2/third-party-bom-3.6.2.pom

<dependency>^M                                                                                                                                                                   
                <groupId>com.sun.java</groupId>^M                                                                                                                                            
                <artifactId>tools</artifactId>^M                                                                                                                                             
                <version>${java.version}</version>^M                                                                                                                                         
                <scope>system</scope>^M                                                                                                                                                      
                <systemPath>${java.home}/../lib/tools.jar</systemPath>^M                                                                                                                     
            </dependency>^M

I was looking at this solution but here JDK8 is not hardcoded in the pom file.

Note: I have verified that my job is not using jre.

Hi,

This looks like a problem external to analysis, although I suppose the SonarQube upgrade prompted you to bump the version of Java you’re analyzing with.

You’ll need to either sort out your pom or compile and test with Java 8 and then run analysis in a new process with Java 11. In the short term the latter may be easier, but in the long term the former is the best route.

 
Ann

Yes, I am following the second solution.

- apk add openjdk11; export JAVA_HOME='/usr/lib/jvm/java-11-jdk' ; mvn -T 1C sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_USER_KEY -Dsonar.java.binaries=target

if you look at the command I am just running the sonar scan using maven. Here it is still using jdk11 but still looking for tools.jar which is not available in jdk11.