projectBaseDir not set correctly in side-by-side maven multi-module configuration

In SonarQube 7.6 I am using the the sonar-maven-plugin to analyze a multi-module maven project. Due to the project directory structure being side-by-side instead of a subdirectory layout this does not set the base project directory correctly.

Example layout:
~/workspace/modules/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>modules</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>modules</name>
    <modules>
        <module>../module1</module>
    </modules>
    <plugins>
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>3.6.0.1398</version>
            </plugin>
    </plugins>
</project>

~/workspace/module1/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.example</groupId>
        <artifactId>module1</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../modules</relativePath>
    </parent>
    <artifactId>module1</artifactId>
    <packaging>jar</packaging>
    <name>module1</name>
</project>

Then running:

cd /home/ds/workspace/modules
mvn clean install sonar:sonar

Results in an error
Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project module1: SCM provider autodetection failed. Both svn and git claim to support this project. Please use “sonar.scm.provider” to define SCM of your project.

So re-running with mvn clean install sonar:sonar -Dsonar.scm.provider=git produces this error caused from jgit:

...
[INFO] Project key: com.example:modules
[INFO] Base dir: /home/ds/workspace
[INFO] Working dir: /home/ds/workspace/modules/target/sonar
...
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] Indexing files of module 'module1'
[INFO]   Base dir: /home/ds/workspace/module1
[INFO]   Source paths: pom.xml, src/main/java
[INFO]   Test paths: src/test/java
[INFO] Indexing files of module 'modules'
[INFO]   Base dir: /home/ds/workspace
[INFO]   Source paths: modules/pom.xml
[INFO] 162 files indexed
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
...
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project modules: Not inside a Git work tree: /home/ds/workspace -> [Help 1]

This is because there is no git project in the /home/ds/workspace directory because the base directory should really be /home/ds/workspace/modules. As a work around I cloned the modules project also in to /home/ds/workspace so that there is a .git work tree. This makes the error go away but then causes jgit issues when it attempts to read blame information due to the files not being found from the directory it’s trying to run blame from (/home/ds/workspace):

[WARNING] Missing blame information for the following files:
[WARNING]   * module1/src/main/java/com/example/SomeClass1.java
[WARNING]   * module1/src/main/java/com/example/SomeClass2.java

To me this is a bug as you can run the maven plugin and it reads the modules just not in to the correct directory structure that is fit for SonarQube. There should at least be an error raised like “Maven multi-module must be in a sub-directory layout.”

Hi @dukethrash

Can you precise how many Git repositories you have? Are /home/ds/workspace/modules and /home/ds/workspace/module1 two separate Git repositories?
If yes, then this is expected to not work. SonarQube doesn’t support analyzing multiple repositories as a single project. You would have to run one analysis for each of your repositories.

Yes they’re two separate repositories. I read somewhere that it’s not supported but I would like to request

  1. That it be supported
  2. Have clearer documentation that it’s not supported, e.g. passing in the baseProjectDir params are not used
  3. Have clearer error handling so that we understand the issue instead of spending efforts foraging the depths of the Internet and playing with different SonarQube configurations

FYI this was working in Sonar 5.3. I’m upgrading to 7.6 and running in to these issues.

I created a ticket:
https://jira.sonarsource.com/browse/SONAR-11760

Thanks for the feedback.

Thanks for the quick response and submitting the ticket!

I am getting the same error but I have a single repo for my sub-modules.

parent:
---->module1
---->module2

Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.6.0.1398:sonar (default-cli) on project notification-parent: Not inside a Git work tree: D:\TeamCity\BuildAgent4\work\a1acdc6ac689cdf5\notifications\notification-client

Please make sure that you have non-committed files in your projects. What I found is that JGit cannot read the blame information for the file when there is a file that is not committed. Do a git status to see.

this is on teamcity with the option to delete all files for all builds