Change Module Directory Path on SonarQubeUI

Versions used:
Sonarqube 7.2, Gradle Plugin 2.6.2, Android Studio 3.1.3, Gradle 4.6, Multi-Project configuration

My Problem:
In a Multi-Proyect gradle configuration I have some libs organized by directories. Lets say;
root
|_AppsDirectory
|____App1
|____App2
|_LibsDirectory
|____Lib1
|____categoryDirectory1
|_______Lib2
|_______categoryDirectory2
|___________Lib3
|____categoryDirectory3
|_______Lib4
|_______Lib5

In order to make sonar work I have to change every moduleKey property to replace their “/” into “:” so that for example Lib2 subproject will set property “sonar.moduleKey” from its default “:LibsDirectory/categoryDirectory1:Lib2” to “:LibsDirectory:categoryDirectory1:Lib2” as slashes ar not allowed for moduleKey

Given this, my proyect buidls successfully and sonar can analyze it but in SonarQube Web, inside “Code” section only those modules directly hanging from its first level directory appears inside its directory (i.e. Lib1 inside LibsDirectory) but all others hangs from root.

In conclusion I’ll see the following:
root
|_AppsDirectory
|____App1
|____App2
|_LibsDirectory
|____Lib1
|_categoryDirectory1
|_Lib2
|_categoryDirectory2
|_Lib3
|_categoryDirectory3
|_Lib4
|_Lib5

So, How can I change a module Path for a module so that it only changes on sonarQubeUI and doesn’t break sonar analysing?

Hi Rubén

Thanks for reporting those issues. The first problem (having slash in module keys) really looks like a bug on our side. I have created a ticket:
https://jira.sonarsource.com/browse/SONARGRADL-53

The second point is more surprising. Could you please run ./gradlew sonarqube -Dsonar.scanner.dumpToFile=sonar.properties and send me (privately) the resulting file (you can check the content and remove sensitive data like sonar.login or sonar.password)

1 Like

Hi Julien

Thanks for your help. Here you can find my sonar.properties:
sonar.properties.txt (1.4 MB)

As I don’t know how to send you privately a message I have uploaded it here and marked my post as offtopic. Hope this is the way of doing it.

This could be of help for my other topic at Sonarqube gradle plugin can't find binaries when using implementation configuration

I think there is a misunderstanding due to the difference between Gradle subproject hierarchy, and physical folder layout.

For now, SonarQube has a concept of modules (that originally comes from Maven FYI) that is a logical view. It is not related to how your folders are structured, but instead how your declare your subprojects in Gradle.

Example:
Let say your physical layout is:

  • folder1
    • folder11
    • folder12
  • folder2
    • folder21
    • folder22

But if you root settings.gradle contains:

include 'folder1/folder11'
include 'folder1/folder12'
include 'folder2/folder21'
include 'folder2/folder22'

Then in SQ you’ll end up with 4 flat modules:

  • folder1/folder11
  • folder1/folder12
  • folder2/folder21
  • folder2/folder22

If you want to mimic the folder hierarchy, you can change your Gradle config by (note that ‘/’ are replaced by ‘:’):

include 'folder1:folder11'
include 'folder1:folder12'
include 'folder2:folder21'
include 'folder2:folder22'

It will make Gradle understand that folder11 is a subproject that is a child of folder1.

And it will also solve your issue of having ‘/’ in module keys.

The good news is that we are working on dropping the concept of modules in SonarQube, and replace it by a hierarchical folder layout. You can follow progress here:
https://jira.sonarsource.com/browse/MMF-365

Mmm the point is that some time ago I already tried to use : instead of / on gradle and I couldn’t be able because it asked me for a certain file on every middle directory and I didn’t want to set it. I’ll try again. Maybe a later change on my code makes it possible to do it.

Thank you very much.