我们的项目具有这样的结构(一个root pom和2个子模块):
默认情况下,声纳似乎使用以下来源:
<sonar.sources>pom.xml,src/main,src/test</sonar.sources>
我们要分析YML文件或其他位置的其他文件。
但是根据https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/
尝试了各种配置之后这个:
<sonar.sources>.</sonar.sources>
<sonar.tests>src/test/java</sonar.tests>
<sonar.test.inclusions>src/test/java</sonar.test.inclusions>
<sonar.exclusions>src/test/java</sonar.exclusions>
产生以下错误:
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project sample: null: MojoExecutionException: NullPointerException
和这个:
<sonar.sources>.</sonar.sources>
<sonar.test.exclusions>src/test/java</sonar.test.exclusions>
产生:
[main] ERROR org.apache.maven.cli.MavenCli - Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project pew-fwk-sample: File sample-impl/src/test/java/com/xxx/sample/FeaturesTest.java can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files -> [Help 1]
您对解决方案有什么想法吗?
答案 0 :(得分:0)
我不会一次更改许多参数。其中一些属性由maven插件提供,不需要更改。我将开始仅使用排除参数。请注意,它使用一些蚂蚁样式模式来排除文件。如果不提供,它将仅适用于该特定文件或文件夹。您链接的页面的底部包含一些示例:
# Exclude all classes ending by "Bean"
# Matches org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java, etc.
sonar.exclusions=**/*Bean.java,**/*DTO.java
# Exclude all classes in the "src/main/java/org/sonar" directory
# Matches src/main/java/org/sonar/MyClass.java, src/main/java/org/sonar/MyOtherClass.java
# But does not match src/main/java/org/sonar/util/MyClassUtil.java
sonar.exclusions=src/main/java/org/sonar/*
# Exclude all COBOL programs in the "bank" directory and its sub-directories
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl, bank/data/REM012345.cob
sonar.exclusions=bank/**/*
# Exclude all COBOL programs in the "bank" directory and its sub-directories whose extension is .cbl
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl
sonar.exclusions=bank/**/*.cbl
因此,<sonar.exclusions>src/main/java/**/*</sonar.exclusions>
之类的东西应排除所有来源。以上是仅排除Dto类的示例。通常,排除项足以缩小焦点范围。但是,如果您想那样进行工作,则以相同的方式进行。