如何让gradle、scoverage和sonarqube正常工作?

mspsb9vt  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(331)

我有一个编译scala代码的多模块gradle构建。我想扫描代码,收集代码覆盖率和饲料的结果到sonarqube。
我的“你好,世界!”因为这个问题就在这里。
我正在执行以下命令:

$ ./gradlew clean build reportScoverage aggregateScoverage
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :a:compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :a:compileTestScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :b:compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :b:compileTestScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :a:compileScoverageScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :a:reportScoverage
[scoverage] Generating scoverage reports...
[scoverage] Written Cobertura XML report to /java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/cobertura.xml
[scoverage] Written XML report to /java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/scoverage.xml
[scoverage] Written HTML report to /java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/index.html
[scoverage] Coverage reports completed

> Task :b:compileScoverageScala
Pruning sources from previous analysis, due to incompatible CompileSetup.

> Task :b:reportScoverage
[scoverage] Generating scoverage reports...
[scoverage] Written Cobertura XML report to /java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/cobertura.xml
[scoverage] Written XML report to /java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/scoverage.xml
[scoverage] Written HTML report to /java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/index.html
[scoverage] Coverage reports completed

> Task :aggregateScoverage
[info] Found 2 subproject report files [/java/opensource/gradle/gradle-scoverage-multi-module/a/build/reports/scoverage/scoverage.xml,/java/opensource/gradle/gradle-scoverage-multi-module/b/build/reports/scoverage/scoverage.xml]
[scoverage] Generating scoverage reports...
[scoverage] Written Cobertura XML report to /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/cobertura.xml
[scoverage] Written XML report to /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/scoverage.xml
[scoverage] Written HTML report to /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/index.html
[scoverage] Coverage reports completed

BUILD SUCCESSFUL in 13s
21 actionable tasks: 21 executed

当我打开 /java/opensource/gradle/gradle-scoverage-multi-module/build/scoverage-aggregate/index.html ,我可以看到:

里面有明显的代码覆盖数字。
所以,我就开始 sonar-scanner 为了向sonarqube发送信息:

$ sonar-scanner -Dsonar.projectName=multi-module \
                -Dsonar.projectKey=multi-module \
                -Dsonar.projectVersion=1.0-SNAPSHOT \
                -Dsonar.sources=src/main/scala \
                -Dsonar.modules=a,b \
                -Dsonar.sourceEncoding=UTF-8 \
                -Dsonar.scala.version=2.11 \
                -Dsonar.scala.scoverage.reportPath=build/scoverage-aggregate/scoverage.xml \
                -Dsonar.host.url=http://localhost:80/

在上面的例子中,我使用默认的docker映像运行它 https://github.com/mwz/sonar-scala-docker ,但我也尝试过在当地安装sonarqube 6.7.6sonar-scala_2.12-6.7.0-assembly.jar 和声纳 7.4sonar-scala_2.12-7.3.1-assembly.jar .
在下面的图片中,没有代码覆盖数字(在上述两个版本的sonarqubes中)。

不过,我报告了一些有效的代码问题(如预期的那样)。
我做错了什么?为什么没有代码覆盖率数字?是否仅支持sbt?我不是在召唤正确的grad尔目标吗?我缺少参数了吗?
正如您在sonar scala的sonarqube示例中看到的,这里有一个“覆盖率”部分显示了一些值(我没有得到这些值):

谁能解释一下吗?很长时间以来我一直在努力纠正这个错误。如果它是一个bug,或者是一个未完成的特性,那么找出这一点也会很有帮助。如果它只在sbt中支持,那么最好知道。
不管怎样,我都非常感谢你的帮助!谢谢!

m3eecexj

m3eecexj1#

回答我的问题,有两件事:
下面是一些例子 sonar-scala 单模块和多模块项目的项目。
如果在windows下执行构建,由于sonar scala存在未解决的问题(64和#65),代码覆盖率将无法工作。

相关问题