Need Help! Separate the multi Project, Post them to Different Sonar project

I have a project with the following structure in gradle (root project, sub-project1 and sub-project2 are sub-project each with their own build.gradle)

  • root project
    • sub-project1
    • sub-project2

I have a sonar analysis setup such that it analyzes the whole project into a project root-analysis on sonarqube. It works ok

With the sub-project1 sub-project growing bigger, I wish to transfer its analysis into a separate sonarqube project sub-project1-analysis and remove it from the root-project-analysis. Is there a way to do so?

And I’ve tried.

  1. In root build.gradle, sonar configuration
    plugins {
  • id ‘org.sonarqube’ version ‘3.2.0’*

  • }*
  • apply plugin: 'org.sonarqube'*

    in root settings.gradle, = ‘root-project’

  •   include ":sub-project1"*
  •   include ":sub-project2"*
  1. In sub-project1 build.gradle ,add these configuration:
    apply plugin: “org.sonarqube”
  •  sonarqube {*
  •      properties {*
  •          // Insert other SonarQube properties here*
  •           property 'sonar.projectName', 'sub-project1'*
  •           property 'sonar.projectKey', 'sub-project1-analysis'*
  •      }*
  •  }*

In the terminal , I type the command " gradle clean :sub-project1:sonarqube*** -Dsonar.login=**** "

It popups error " * What went wrong: Task ‘sonarqube’ not found in project ‘:sub-project1’. "

I’m currently using sonar-gradle plugin 3.2.0, and it’d be great if I didn’t have to update that.



I think you’re going to need to cd into sub-project1 and trigger analysis from there - after you’ve built root project, of course.



Thanks for your reply.
When I cd into sub-project1, and execute the “gradle sonarqube” , it popups " A problem occurred evaluating root project ‘sub-project1’.
> Could not get unknown property ‘sourceSets’ for root project ‘sub-project1’ of type org.gradle.api.Project. "

Best regards,

Hi Fangcao,

Sorry, I’m not a Gradle expert. I thought that would work; clearly I was wrong.

I guess you’ll need to analyze twice from project root, once passing commandline args

-Dsonar.projectKey=root -Dsonar.exclusions=sub-project2/**/*.*

And once with

-Dsonar.projectKey=sub-project2 -Dsonar.inclusions=sub-project2/**/*.*

Obviously, you’ll need to tweak the paths a little. Early in the analysis log you should see logging that helps you understand how they’re being interpreted.


Ok, Thanks for your reply, I will try it.