Reputation: 43
I have been trying to set up sonar-scanner for a Maven project containing a java module (core) and a javascript module (web).
I am able to get either java coverage data scanned and presented on my local sonarqube server, or javascript, but not both.
Here is my sonar-project.properties file, where the sonar.modules property can have one of 4 values:
### below: select just one of the 4 possible values for sonar.modules
sonar.modules = core --> get java coverage data
sonar.modules = web --> get javascript coverage data
sonar.modules = core,web --> get only java coverage data
sonar.modules = web,core --> get only java coverage data
sonar.sources=src
# javascript coverage report
web.sonar.exclusions=src/main/webapp/js/lib/**/*.js
web.sonar.javascript.lcov.reportPath = test-output/coverage/lcov.info
# java coverage report
core.sonar.java.binaries = target/classes
core.sonar.java.libraries = ../web/target/scheduler-web-3.5.0-SNAPSHOT/WEB-INF/lib
core.sonar.java.test.libraries = ../web/target/scheduler-web-3.5.0-SNAPSHOT/WEB-INF/lib
core.sonar.jacoco.reportPath = target/jacoco.exec
core.sonar.junit.reportsPath = target/surefire-reports
core.sonar.jacoco.reportMissing.force.zero = true
The key to my solution, based on the accepted answer below :
No changes to the top-level POM.
Added to web/pom.xml:
<properties> <sonar.javascript.lcov.reportPath>test-output/coverage/lcov.info</sonar.javascript.lcov.reportPath> </properties>
Essentially sonar did not know where to find my lcov file.
Upvotes: 4
Views: 8708
Reputation: 26843
You should not use the SonarQube Scanner with a dedicated sonar-project.properties
file to run your analysis - but instead rely on the Scanner for Maven.
To see how to do this, simply take a look at how SonarQube itself (that contains both Java and JS) is analyzed:
<properties>
<!-- self-analysis -->
<sonar.sources>src/main/js,src/main/less</sonar.sources>
<sonar.tests>src/main/js</sonar.tests>
<sonar.test.inclusions>src/main/js/**/__tests__/**</sonar.test.inclusions>
<sonar.exclusions>src/main/js/libs/third-party/**/*,src/main/js/libs/require.js,src/main/js/**/__tests__/**</sonar.exclusions>
<yarn.script>build</yarn.script>
</properties>
Upvotes: 1