I've been working on this for hours, and every solution I've tried that I've found online makes no difference.
I have a project which is written in Kotlin. I have the Kotlin plugin installed on my sonar server. I am using JaCoCo plugin to generate code coverage report for sonar.
My project is multi-module, but only 1 sub-module has unit tests, and so I have defined my JaCoCo plugin there.
I am also using the Surefire plugin.
Here are my properties in my pom.xml
<properties>
<sonar.java.binaries>target/classes</sonar.java.binaries>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.jacoco.reportPath>target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>kotlin</sonar.language>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.verbose>true</sonar.verbose>
<sonar.jacoco.reportsPath>target</sonar.jacoco.reportsPath>
<sonar.junit.reportsPath>target/surefire-reports</sonar.junit.reportsPath>
<sonar.surefire.reportsPath>target/surefire-reports</sonar.surefire.reportsPath>
<surefireArgLine/>
</properties>
Here is my surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
And here is my JaCoCo plugin:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
After running my unit tests, I generate my sonar report like so:
mvn sonar:sonar -Dsonar.projectName=vqs -Dsonar.projectKey=vqs
And Sonar reports no coverage.
At one point in time, I was getting code coverage data. At this time, the project was a single module, and was potentially not using surefire (I can't remember for sure).
Hoping somebody will see my error and help me out!
Thanks, Tonya
EDIT, adding console output:
tohrel@ussd-olm-016438:~/projects/project-name-redacted/vqs-api$ mvn sonar:sonar -Dsonar.projectName=vqs -Dsonar.projectKey=vqs
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Variant Query Service - API 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.4.0.905:sonar (default-cli) @ vqs-api ---
[INFO] User cache: /Users/tohrel/.sonar/cache
[INFO] SonarQube version: 7.2.1
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Publish mode
[INFO] Load global settings
[INFO] Load global settings (done) | time=143ms
[INFO] Server id: AWT2VY5OzSeF07PuEM-H
[INFO] User cache: /Users/tohrel/.sonar/cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=82ms
[INFO] Load/download plugins (done) | time=132ms
[INFO] Loaded core extensions:
[INFO] Process project properties
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=140ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=63ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=618ms
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=19ms
[INFO] Project key: vqs
[INFO] Project base dir: /Users/tohrel/projects/project-name-redacted/vqs-api
[INFO] ------------- Scan vqs
[INFO] Load server rules
[INFO] Load server rules (done) | time=178ms
[INFO] Base dir: /Users/tohrel/projects/project-name-redacted/vqs-api
[INFO] Working dir: /Users/tohrel/projects/project-name-redacted/vqs-api/target/sonar
[INFO] Source paths: src/main
[INFO] Test paths: src/test
[INFO] Source encoding: UTF-8, default locale: en_US
[INFO] Language is forced to kotlin
[INFO] Index files
[INFO] 254 files indexed
[INFO] Quality profile for kotlin: Sonar way
[INFO] Sensor Kotlin Sensor [kotlin]
[INFO] 208 source files to be analyzed
[INFO] Sensor Kotlin Sensor [kotlin] (done) | time=2693ms
[INFO] 208/208 source files have been analyzed
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=4ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=90ms
[INFO] Sensor CPD Block Indexer
[INFO] Sensor CPD Block Indexer (done) | time=0ms
[INFO] 57 files had no CPD blocks
[INFO] Calculating CPD for 151 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 484ms, dir size=658 KB
[INFO] Analysis reports compressed in 582ms, zip size=444 KB
[INFO] Analysis report generated in /Users/tohrel/projects/project-name-redacted/vqs-api/target/sonar/scanner-report
[INFO] Analysis report uploaded in 27ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=vqs
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://localhost:9000/api/ce/task?id=AWVagYWzPCQMqzjb5q73
[INFO] Task total time: 7.582 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.536 s
[INFO] Finished at: 2018-08-20T20:22:42-07:00
[INFO] Final Memory: 56M/869M
[INFO] ------------------------------------------------------------------------
sonar.jacoco.reportPath
andsonar.jacoco.reportsPath
(first deprecated in favor of second) are properties of Java plugin, which can't and doesn't importexec
for Kotlin, however you're forcing language of your project to be Kotlin bysonar.language=kotlin
. Second - as per docs.sonarqube.org/display/PLUG/…sonar.jacoco.reportPaths
should be for exampletarget/jacoco.exec
but not justtarget
. – Daric