首页 > 解决方案 > sonar-maven-plugin:如何在包含模式中使用项目相对路径?

问题描述

我有一个相当大的多模块多语言 maven 项目(总共约 100 个模块),我想使用 SonarQube 进行分析,因为扫描仪不会自动发现所有语言的所有文件(即不适用于 Groovy 和 Kotlin) ,我必须告诉它在哪里查找文件。

大多数模块包含 asrc/main/和 asrc/test/目录的典型组合,但不一定两者都包含,这使得在顶级 pom 中简单地声明<sonar.sources>pom.xml,src/main/</sonar.sources>和作为属性是不可能的,因为缺少目录会导致 maven 中止并出现错误。<sonar.tests>src/test/</sonar.tests>

根据https://stackoverflow.com/a/37545474,解决此问题的一种可能方法是设置...

  • sonar.sources成为.
  • sonar.inclusions成为src/main/**
  • => 这将包括 SQ 在 src/main 文件夹中的模块中找到的所有已知文件(如果存在)

并且只使用

<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在分析所有子模块中的所有文件的同时使用属性来消除警告?

标签: mavensonarqubesonarqube-scan

解决方案


绿色,

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

<properties>
    <sonar.projectBaseDir>.</sonar.projectBaseDir>
</properties>

参考: https ://community.sonarsource.com/t/relationship-between-projectbasedir-sources-and-exclusions/12785


推荐阅读