sonarqube 忽略 sonar.junit.reportPaths [英] sonarqube ignores sonar.junit.reportPaths

查看:131
本文介绍了sonarqube 忽略 sonar.junit.reportPaths的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 gradle 项目,它应用了 sonarqube gradle 插件,版本 2.6.
我针对我团队的 sonarqube 服务器版本 6.4(内部版本 25310)运行它.

I have a gradle project which applies the sonarqube gradle plugin, version 2.6.
I run it against my team's sonarqube server, version 6.4 (build 25310).

根据文档,新版本的 sonarqube 接受属性 sonar.junit.reportPaths 而不是 sonar.junit.reportsPath.

According to documentation, new versions of sonarqube accept the property sonar.junit.reportPaths instead of sonar.junit.reportsPath.

我的构建运行 2 个测试任务:testintegrationTest.每个测试任务将其 xml 输出到不同的目录:分别为 build/test-results/testbuild/test-results/integrationTest.
我配置了 sonarqube 插件来获取这两个目录:

My build runs 2 test tasks: test and integrationTest. Each test task outputs its xml into a different directory: build/test-results/test and build/test-results/integrationTest respectively.
I configured the sonarqube plugin to pick up both these directories:

project.sonarqube {
     properties {
         property 'sonar.junit.reportsPath', ['build/test-results/test',
                                              'build/test-results/integrationTest']

         // configure additional integration test properties that seem to be required
         Collection<File> integrationTestSourceDirs = project.sourceSets.integrationTest.allJava.srcDirs.findAll { File dir -> dir.exists() }
         properties['sonar.tests'] += integrationTestSourceDirs
         Collection<File> integrationTestsClasses = project.sourceSets.integrationTest.output.classesDirs.files.findAll { File file -> file.exists() }
         properties['sonar.java.test.binaries'] += integrationTestsClasses
     }       
}

这不起作用.在 sonarqube UI 中,我只看到单元测试(来自 test 目录),看不到任何集成测试.
我确保我的 integrationTest 目录包含有效的测试报告,而且确实如此.

This does not work. In sonarqube UI I only see unit tests (from the test directory) and don't see any integration tests.
I made sure that my integrationTest directory contains valid test reports, and it does.

似乎 sonarqube 仍然使用旧参数 sonar.junit.reportsPath (默认情况下由 gradle 插件分配值 build/test-results/test).我可以这么说,因为如果我删除这个参数,我在 UI 中根本看不到任何单元测试.这就是我删除旧参数的方式:

It seems like sonarqube still uses the old parameter sonar.junit.reportsPath (which by default is assigned by the gradle plugin with the value build/test-results/test). I can tell this because if I remove this parameter I don't see any unit tests at all in the UI. This is how I removed the old parameter:

project.sonarqube {
   properties {
        properties.remove("sonar.junit.reportsPath")
   }
}    

作为一种解决方法,我将我的 integrationTest 任务配置为将其输出放入与单元测试相同的目录中:build/test-results/test.完成此操作后,所有测试(包括集成测试)都被 sonarqube 拾取,我可以在 UI 中看到它们.

As a workaround, I configured my integrationTest task to put its output into the same directory as unit tests: build/test-results/test. After doing this, all tests, including integration tests are picked up by sonarqube, and I can see them all in the UI.

但是,我更愿意将不同测试任务的输出保存在不同的目录中.
所描述的行为是故意的,还是错误?

However, I would prefer to keep outputs of different test tasks in different directories.
Is the described behavior intentional, or is it a bug?

推荐答案

你的 SonarJava 插件太旧了.新属性仅从 4.11 开始可用.在 4.10 中,仅评估旧属性,因此忽略新属性.Gradle 插件只是设置属性.评估发生在从 SonarQube 服务器下载的代码中,因此被忽略.

Your SonarJava plugin is too old. The new property is only available from 4.11 on. In 4.10 only the old property is evaluated, so the new one is ignored. The Gradle plugin just sets the properties. The evaluation happens in the code that is downloaded from the SonarQube server and thus ignored.

这篇关于sonarqube 忽略 sonar.junit.reportPaths的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆