Jacoco 0.8.8 with maven having zero code coverage with JDK17 and Sonarqube 9.9.2.77730

1.8k Views Asked by At

I am upgrading my spring boot microservice from Java11 to Java17, service build and run successfully with use of maven. I have added jacoco-maven-plugin plugin for unit test cases coverage but when I tried in sonarqube I am seeing code coverage is zero. The same change is working fine with Java 11. My configuration is as below.

Maven: 3.6.1
Java: 17.0.7
maven-surefire-plugin: 2.22.2
jacoco-maven-plugin: 0.8.8
sonarqube: 9.9.2.77730

I am using below command for test case and coverage.

mvn clean test


mvn clean verify sonar:sonar \
  -Dsonar.projectKey=test-service \
  -Dsonar.host.url=http://localhost:9000 \
  -Dsonar.login=sqa_57657e1f59a8f2b720badb3b7b2043e004e3832f

Maven properties are as below:

<maven.surefire.version>2.22.2</maven.surefire.version>
<sonar.jacoco.reportPath>target/coverage-reports/jacoco-unit.exec</sonar.jacoco.reportPath>
<sonar.test.reportPath>coverage-reports/</sonar.test.reportPath>
<sonar.jacoco.coverage.output.directory>target/site/jacoco-ut</sonar.jacoco.coverage.output.directory>
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
<sonar.projectName>test-service</sonar.projectName>
<sonar.skip>false</sonar.skip>

and test profile is as below:

<profiles>
    <profile>
        <id>sonar-build</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
            <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven.surefire.version}</version>
                    <configuration>
                        <!-- Jacoco prepare-agent builds some command-line params without -->
                        <!-- which jacoco will not instrument. Hence it is important to add -->
                        <!-- those command-line params here (${argLine} holds those params) -->
                        <argLine>${surefireArgLine} -Xms256m -Xmx2048m</argLine>
                        <argLine>
                            --add-opens java.base/java.time=ALL-UNNAMED
                            --add-opens java.base/java.time.format=ALL-UNNAMED
                            --add-opens java.base/java.util=ALL-UNNAMED
                            --add-opens java.base/java.util.stream=ALL-UNNAMED
                            --add-opens java.base/java.lang=ALL-UNNAMED
                        </argLine>
                        <forkCount>1</forkCount>
                        <runOrder>random</runOrder>
                        <destFile>${sonar.test.reportPath}</destFile>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.8.8</version>
                    <configuration>
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                        <dataFile>${sonar.jacoco.reportPath}</dataFile>
                        <append>true</append>
                    </configuration>
                    <executions>
                        <execution>
                            <id>jacoco-initialize</id>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <propertyName>surefireArgLine</propertyName>
                            </configuration>
                        </execution>
                        <execution>
                            <id>jacoco-report</id>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${sonar.jacoco.coverage.output.directory}</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
0

There are 0 best solutions below