在 Sonarqube 6.3 中使用 sonar.test.exclusions [英] Using sonar.test.exclusions with Sonarqube 6.3

查看:52
本文介绍了在 Sonarqube 6.3 中使用 sonar.test.exclusions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在评估 Sonarqube 6.3(对我当前的 5.5 实例进行了重大升级),我在尝试制定 sonar.test.exclusions 设置的功能时感到困惑.p>

有个问题:声纳Maven 插件:如何排除测试源目录? 这似乎表明它用于从分析中排除测试文件(这是我所追求的 - 我不希望我的声纳规则集在我的单元上运行测试).文档 https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus 还表示它用于排除单元测试文件"(也许可以将其扩展以使其更清晰?)

问题是,当我添加 sonar.test.exclusions 的值为 **/src/test/** 然后运行我的分析时,我仍然会收到代码异味等被发现:

  • Foo/src/test/java/foo/bar/BarTest.java
  • Foo/src/test/java/lah/LahTest.java

等等

当我改用 sonar.exclusions 时,它们不会出现.为什么 sonar.test.exclusions 没有达到我的预期?

解决方案

首先:如果你有一个 Maven 项目,你应该使用 Maven 的扫描仪(mvn sonar:sonar).它将简化您的配置,并会自动将 src/test/java 文件夹注册为测试目录.

现在,如果您想手动进行配置,或者了解幕后发生的事情,这里是解释:SonarQube 扫描仪使用 2 组文件,主要和测试.主要源文件使用属性 sonar.sources 进行配置.使用 sonar.tests 配置测试源文件.

除此之外,您还可以使用 sonar.[test.]exclusions 属性过滤一些内容.

在您的情况下,您的问题是 Foo/src/test/java/foo/bar/BarTest.java 似乎被视为主要源文件.这就是 sonar.test.exclusions 无效的原因.

I'm currently evaluating Sonarqube 6.3 (a big upgrade from my current 5.5 instance) and I'm getting confused trying to work out the functionality of the sonar.test.exclusions setting.

There's this question: Sonar Maven Plugin: How do I exclude test source directories? which seems to indicate that it is used to exclude test files from analysis (which is what I'm after - I don't want my sonar ruleset run over my unit tests). The documentation https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus also indicates that it is used to 'exclude unit test files' (perhaps this can be expanded upon to make it clearer?)

Thing is, when I add sonar.test.exclusions with a value of **/src/test/** and then run my analysis, I'm still getting code smells and the like being found for:

  • Foo/src/test/java/foo/bar/BarTest.java
  • Foo/src/test/java/lah/LahTest.java

etc.

When I use sonar.exclusions instead, they don't show up. Why is sonar.test.exclusions not doing what I expect?

解决方案

First of all: if you have a Maven project, you should use the scanner for Maven (mvn sonar:sonar). It will simplify your configuration, and will automatically register src/test/java folder as a test directory.

Now if you want to do the configuration manually, or understand what is going on under the hood, here is the explanation: SonarQube scanner work with 2 sets of files, main and test. Main source files are configured using the property sonar.sources. Test source files are configured using sonar.tests.

On top of that, you can filter some content using the sonar.[test.]exclusions properties.

In you case your problem is that Foo/src/test/java/foo/bar/BarTest.java seems to be considered as a main source file. That's why sonar.test.exclusions has no effect.

这篇关于在 Sonarqube 6.3 中使用 sonar.test.exclusions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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