maven - Sonar Maven 插件 : How to use project-relative paths in inclusion patterns?

标签 maven sonarqube sonarqube-scan

我有一个相当大的多模块多语言 maven 项目(总共约 100 个模块),我想使用 SonarQube 进行分析,因为扫描仪不会自动发现所有语言的所有文件(即不适用于 Groovy 和 Kotlin) ,我必须告诉它在哪里查找文件。
大多数模块包含 src/main/ 的典型组合和 src/test/目录,但不一定都是,这使得简单地声明 <sonar.sources>pom.xml,src/main/</sonar.sources> 是不可能的。和 <sonar.tests>src/test/</sonar.tests>作为顶级 pom 中的属性,因为缺少目录会导致 maven 中止并出现错误。
根据https://stackoverflow.com/a/37545474解决此问题的一种可能方法是
放 ...

  • sonar.sources to be .
  • sonar.inclusions to be src/main/**
  • => this will include all the known files that SQ finds in your modules in the src/main folder if it exists

并且只使用
<sonar.sources>.</sonar.sources>
<sonar.tests>.</sonar.tests>
<sonar.inclusions>pom.xml,src/main/**</sonar.inclusions>
<sonar.test.inclusions>src/test/**</sonar.test.inclusions>
在顶级 pom 中确实按预期工作(所有应该分析的文件都被发现,并且由于缺少目录而没有报告错误),但它也会导致以下警告,该警告也显示在 SonarQube 中:[WARNING] Specifying module-relative paths at project level in the property 'sonar.inclusions' is deprecated. To continue matching files like 'frontend/pom.xml', update this property so that patterns refer to project-relative paths.到目前为止,我尝试的所有路径要么导致总共分析较少的文件,要么导致错误,因为单个文件将被多次索引,因为包含模式产生的非不相交集。因此问题...
如何使用 *.inclusions属性以摆脱警告,同时仍分析所有子模块中的所有文件?

最佳答案

绿色,
我在使用 Jenkins 管道时遇到了同样的问题。我解决了包括“projectBaseDir”参数,如下所示:

<properties>
    <sonar.projectBaseDir>.</sonar.projectBaseDir>
</properties>
引用: https://community.sonarsource.com/t/relationship-between-projectbasedir-sources-and-exclusions/12785

关于maven - Sonar Maven 插件 : How to use project-relative paths in inclusion patterns?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62575353/

相关文章:

java - Sonarqube 集成和 startSonar.bat 失败错误(0x2)

mysql - Sonar Tomcat 安装失败

java - Sonar :sonar work?如何

java - Hadoop build Failing in Windows : zconf. h 从 native.sln 中丢失?

java - "Broken"本地存储库 - 我如何注意到?我怎样才能阻止它发生?

java - 如何使用 Maven 运行方法?

scala - 无法注册扩展名org.sonar.plugins.scala.cobertura.CoberturaSensor

sonarqube - 使用 MSBuild Scanner 时如何排除单个文件

maven - SonarQube Scanner for Maven 和 SonarTsPlugin 无法运行节点

java - 使用 WebAppCreator 制作的 GWT Maven 项目在开发模式下不工作