【问题标题】:sonar-maven-plugin: How to use project-relative paths in inclusion patterns?sonar-maven-plugin:如何在包含模式中使用项目相对路径?
【发布时间】:2020-10-15 21:51:48
【问题描述】:

我有一个相当大的多模块多语言 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 成为.
  • 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 属性来消除警告,同时仍分析所有子模块中的所有文件?

【问题讨论】:

    标签: maven sonarqube sonarqube-scan


    【解决方案1】:

    绿色,

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-03
      • 2016-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      相关资源
      最近更新 更多