Sonarqube 如何正确配置 gradle 子项目? [英] Sonarqube how to configure gradle sub-projects correctly?

查看:33
本文介绍了Sonarqube 如何正确配置 gradle 子项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 gradle 项目结构如下所示:

My gradle project structure looks something like this:

geode-core
geode-lucene
extensions/geode-modules
extensions/geode-modules-session

对于 extensions 子项目,因此将使用 extensions/geode-modules:build 引用 gradle 任务.

For extensions sub-projects, gradle tasks would thus be referenced with extensions/geode-modules:build for example.

当我尝试在 Gradle 中使用 SonarQube 时,出现以下错误(这是 1.2 SonarQube Gradle 插件):

When I try and use SonarQube in Gradle I'm getting the following error (this is the 1.2 SonarQube Gradle plugin):

Validation of project reactor failed:
  o "io.pivotal.gemfire:extensions/geode-modules" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.
  o "io.pivotal.gemfire:extensions/geode-modules-session" is not a valid project or module key. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.

所以模块名称中的 / 引起了问题.为了解决这个问题,我尝试遵循此线程上的解决方案:http://sonarqube-archive.15.x6.nabble.com/Is-not-a-valid-project-or-module-key-when-Upgrade-sonar-3-0-to-4-0-td5021412.html

So the / in the module name is causing a problem. To fix it I tried following the solution on this thread: http://sonarqube-archive.15.x6.nabble.com/Is-not-a-valid-project-or-module-key-when-Upgrade-sonar-3-0-to-4-0-td5021412.html

我的 gradle 配置现在如下所示:

My gradle config now looks like this:

sonarqube {
  properties {
    property "sonar.modules", "extensions.geode-modules"
    ...
    property "extensions.geode-modules.sonar.projectName", "geode-modules"
    property "extensions.geode-modules.sonar.sources", "src/main/java"
  }
}

同样的错误.此外,这也不起作用:

Same error. Also, this didn't work either:

sonarqube {
  properties {
    property "sonar.modules", "extensions/geode-modules"
    ...
    property "extensions/geode-modules.sonar.projectName", "geode-modules"
    property "extensions/geode-modules.sonar.sources", "src/main/java"
  }
}

关于如何让它正常工作的任何想法?

Any thoughts on how to get this to work properly?

推荐答案

一种通用的方法是替换模块名称中的所有斜杠.这样,您无需配置各种属性.将此部分添加到您的根 build.gradle 文件中:

A generic approach is to replace all slashes in a module name. This way, you don't need to configure the various properties. Add this part in your root build.gradle file:

subprojects {

    sonarqube {
        String regex = "(.*)/(.*)"
        String projectKey = project.name.replaceAll(regex, "$1:$2")
        String sonarModuleKey = rootProject.group + ':' + rootProject.name + ':' + projectKey

        properties {
            property "sonar.moduleKey", sonarModuleKey
        }
    }
}

这篇关于Sonarqube 如何正确配置 gradle 子项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆