Resolution conflict between sonar.projectBaseDir and project.settings

Hello everyone and happy new year :slight_smile:

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

SonarQube Community 10.3, Jenkins SonarQube Scanner

  • Issue

I have a monorepo consisting of several packages, each having its own SonarQube project.

repository root
- /packages
-- /package1
--- sonar-project.properties
--- /src
-- /package2
--- sonar-project.properties
--- /src

The Jenkins job (for the whole repository) runs one SonarQube analysis per package in the repository. Each step consists of picking up the sonar-project.properties file of the corresponding package.
What this Jenkins step does is set the project.settings property with, here, packages/package1.sonar-project.properties

Now for the content of the properties file, the following does not work

package1/sonar-project.properties
sonar.sources=src

Because the scanner resolves sources from the root of the repository, and not from the directory where project.settings was found. (Nothing alarming so far)

Now, according to the Analysis parameters documentation, the sources are resolved from sonar.projectBaseDir, which very logically would correspond to the folder where all the files pertaining to that Sonar project belong.

So I would expect the following to work:

package1/sonar-project.properties
sonar.projectBaseDir=packages/package1
sonar.sources=src

But it doesn’t, the sources are still resolved from the repo root.
ERROR: The folder 'src' does not exist for 'package1' (base directory = /my/workspace/root)

To understand why, I had to stumble upon an old StackOverflow thread which mentions that project.settings and sonar.projectBaseDir are incompatible.

Unfortunately it seems to still be the case even though it is not mentioned anymore in the documentation.

The following works for me:

package1/sonar-project.properties
sonar.sources=packages/package1/src

But it limits the practicality and maintainability of the config files, because a lot of properties will have that baseDir path duplicated.

  • What I expected

Firstly, this limitation should be explicit in the documentation, can it be updated?
Then, is there a way for this limitation to be fixed or worked around in a future SonarQube version?

Thank you very much!

1 Like

Hey there.

The scanner goes looking in sonar.projectBaseDir for the sonar-project.properties file, which is why you can’t use both. It would probably make more sense for the Jenkins extension to ask you for the project base directory (using project.settings, which the Jenkins extension is doing, is really unique and quite outdated at this point).

To me, it would make sense that you do what is outlined in that StackOverflow thread – setting sonar.projectBaseDir as a configuration specific to your Jenkins pipeline (in the Analysis Properties) section. This will not overwrite what is in your sonar-project.properties file.

Worked like a charm, thank you!

I’ll see that we look to update that Jenkins plugin, might need a bit of dusting :slight_smile:

Well, it’s our plugin (Sonar’s)… and I think the latest version still works like this. I’ll see if I can find the right ears!