Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarqube how to configure gradle sub-projects correctly?

My gradle project structure looks something like this:

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

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

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.

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

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?

like image 836
Jens D Avatar asked Oct 15 '25 16:10

Jens D


1 Answers

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
        }
    }
}
like image 102
user2978801 Avatar answered Oct 18 '25 08:10

user2978801