Java – Upgrading to Java 11, sonarqube, jacoco with maven causing errors

jacocojavamavensonarqube

After upgrading Java from 8 to 11. sonar:sonar is not working getting exception
in the end.

Java 1.8 is working fine with Sonarqube 7.7, now with java 11 and sonarqube 7.8 it is failing with exception

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project xxxx: Unable to read ….\target\jacoco.exec to determine JaCoCo binary format.: EOFException -> [Help 1]

Using below properties for java 11

<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>     
<runSuite>**/*Test.class</runSuite>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis
<sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.language>java</sonar.language>

Below plugins using jacoco

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <release>${java.version}</release>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <argLine>--illegal-access=permit</argLine>
        <includes>
            <include>${runSuite}</include>
        </includes>
        <forkCount>0</forkCount>
    </configuration>
</plugin>
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.8.4</version>
    <configuration>
        <destFile>${sonar.jacoco.reportPaths}</destFile>
        <append>true</append>
    </configuration>
    <executions>
        <execution>
            <id>agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Am I missing any configuration in pom file to run sonarqube using jacoco

Best Answer

Removing sonar.coverage.jacoco.xmlReportPaths and maven-surefire-plugin gave the code coverage. Issue is fixed.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <argLine>--illegal-access=permit</argLine>
        <includes>
            <include>${runSuite}</include>
        </includes>
        <forkCount>0</forkCount>
    </configuration>
</plugin>

Useful links:

https://52.213.100.93/browse/MMF-1651

https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven