SonarQube test case rule does not take @Test annot

2019-06-01 11:53发布

I am seeing an issue similar to this question. When running mvn sonar:sonar as a Jenkins post-build action on a Maven project, @Test and @Ignore annotations in JUnit tests are recognized properly. When I run a SonarQube preview on the same project via the SonarQube Eclipse plugin, the annotations are not recognized and there are (erroneous) Major bug issues shown.

I have followed the directions for installing and configuring the Eclipse plugin here and here. Am I missing configuration somewhere?

  • SonarQube server 5.1.2 with Java plugin 3.4
  • Eclipse Luna 4.4.0
  • m2e 1.6.1.20150625
  • SonarQube Integration for Eclipse 3.5.0.20150804-1512-RELEASE (4 features)
  • Apache Maven 3.2.2 (for both Jenkins and Eclipse)

Update:

My multi-module project is structured like this:

Top level aggregator POM (is not the parent)
    Project parent POM
    Module 1 (extends project parent)
    Module 2 (extends project parent)

When the top level directory is expanded, there is no Maven Dependencies child directory, because the top level POM doesn't include any dependencies (only a modules block). I was running the SonarQube analysis at the top level, so the SonarQube Eclipse plugin didn't have the dependencies needed, and I saw the errors. If I run the analysis on one of the individual modules, I see only the expected errors, not the extra ones.

1条回答
甜甜的少女心
2楼-- · 2019-06-01 12:41

This issue is usually caused by missing test classpath (missing or bad sonar.java.test.libraries/binaries). Updating to SQ Java plugin 3.5 will at least hide the problem thanks to https://jira.sonarsource.com/browse/SONARJAVA-1193.

Update:

If you are using m2e, when importing a multi module Maven project you should get one Eclipse project per Maven module. And then you should run SonarQube analysis on each leaf modules.

查看更多
登录 后发表回答