Make SonarQube Gradle plugin available in root project and subprojects
Asked Answered
S

0

7

When using Maven with a multi-module project I can simply add the Sonar plugin to the parent POM:

<plugin>
    <groupId>org.sonarsource.scanner.maven</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
    <version>3.4.0.905</version>
</plugin>

And then run it in the project root to get aggregated results:

.../project$ mvn sonar:sonar

Or for a specific module:

.../project$ mvn sonar:sonar -f module/pom.xml

However this doesn't seem possible with Gradle.

If I only apply the SonarQube plugin (apply plugin: 'org.sonarqube') in the root project, I get aggregated results when running it in the root project, but the plugin is not available in the subprojects:

.../project$ ./gradlew :module:sonarqube
FAILURE: Build failed with an exception.

* What went wrong:
Task 'sonarqube' not found in project ':module'.
...

If I only apply the SonarQube plugin in the subprojects, running it on the root project doesn't give aggregated results.

If I apply the SonarQube plugin in allprojects (root project + subprojects), trying to run any Gradle command outputs:

FAILURE: Build failed with an exception.

* Where:
Build file '.../project/build.gradle' line: 38

* What went wrong:
A problem occurred evaluating root project 'project'.
> Failed to apply plugin [id 'org.sonarqube']
   > Cannot add extension with name 'sonarqube', as there is an extension already registered with that name.

Is there a way to make the SonarQube plugin for Gradle to work in both root project and subprojects like it does for Maven?

Solmization answered 19/2, 2018 at 12:35 Comment(1)
Did you ever find a solution? I am facing the same issue.Micahmicawber

© 2022 - 2024 — McMap. All rights reserved.