I have a multi-module maven project that has both in module unit tests and end-to-end service tests (not quite integration tests since they don't actually integrate with anything) where we mock at the boundaries of the particular service being tested. This latter set of tests (using mockmvc to exercise all layers before deployment) generate a jacoco.exec (or jacoco-it.exec depending on the maven configuration I try) that clearly shows that the tests contribute to code coverage. In fact that vast majority of coverage is in this layer (roughly 40% per jacoco).
When I run sonar analysis on the project locally, or via jenkins, I get the following for the top level tests:
[INFO] Sensor JaCoCoSensor [java]
[INFO] Analysing /Users/tokkov/Documents/workspace/platform/customer/assemblies/service/target/jacoco.exec
[WARNING] Coverage information was not collected. Perhaps you forget to include debug information into compiled classes?
[INFO] Sensor JaCoCoSensor [java] (done) | time=164ms
So sonar finds the jacoco analysis. It finds the compiled code (unpacked the jars into the build directory and specified location with sonar.java.binaries), the compiled code does have debug info (verified with javap -l), but it still throws up its hands and moves on.
Any ideas why sonar ignores the jacoco report? Am I missing a configuration somewhere? It happily gobbles up all of the jacoco.exec reports in the other modules, just not this one.
<sonar.java.binaries>${project.build.directory}/class-fix</sonar.java.binaries>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${project.build.directory}/jacoco.exec</sonar.jacoco.reportPaths>
The versions: Sonarqube v 7.1 (build 11001), JaCoCo maven plugin v 0.8.1
答案 0 :(得分:0)
这是pom.xml中对我有用的配置:
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
在同一pom.xml中的和jacoco插件设置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<id>agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
答案 1 :(得分:0)
问题似乎出在嵌套Maven模块上。该项目结构高度嵌套在自然中,我相信这有助于从心理上加强他们正在实施的六边形体系结构的隔离。这导致了几个仅包含其他模块的模块,而声纳插件似乎在代码的关联方式中迷失了。一旦我删除了任何不包含代码的模块以平整文件夹结构,报告就会像应该的那样通过。
在第二个项目中,我指定使用单个jacoco.exec文件,以便jacoco可以在声纳介入之前对其进行汇总。这也解决了这个问题,并允许团队保留高度嵌套的Maven结构。
在这两种情况下,问题似乎都是声纳不处理跨模块代码引用以进行覆盖,除非在声纳分析之前汇总了jacoco结果。
这是端到端服务测试中的一个重要问题,它使代码分离到离散模块的好处无法实现。
tl;博士 Sonar无法处理多层嵌套的Maven模块。并完全忽略了包含测试的模块之外的代码。