Sonar-maven-plugin: error: 'other' has different root"

When building a Maven project on a Jenkins Windows node, the following error is reported:

INFO | maven : [INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ XXXXX ---
INFO | maven : [INFO] User cache: C:\Users\XXXX\.sonar\cache
INFO | maven : [INFO] SonarQube version: 8.4.1
INFO | maven : [INFO] ------------------------------------------------------------------------
INFO | maven : [INFO] Reactor Summary:
INFO | maven : [INFO].--------------------------
INFO | maven : [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project XXXXX: 'other' has different root -> [Help 1]

The stack trace is:

Caused by: java.lang.IllegalArgumentException: 'other' has different root
    at sun.nio.fs.WindowsPath.relativize(WindowsPath.java:392)
    at sun.nio.fs.WindowsPath.relativize(WindowsPath.java:44)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.lambda$removeTarget$2(MavenProjectConverter.java:476)
    at java.util.Collection.removeIf(Collection.java:414)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.removeTarget(MavenProjectConverter.java:474)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.sourcePaths(MavenProjectConverter.java:520)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.mainSources(MavenProjectConverter.java:502)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.synchronizeFileSystemAndOtherProps(MavenProjectConverter.java:371)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.computeSonarQubeProperties(MavenProjectConverter.java:250)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.configureModules(MavenProjectConverter.java:206)
    at org.sonarsource.scanner.maven.bootstrap.MavenProjectConverter.configure(MavenProjectConverter.java:134)
    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.collectProperties(ScannerBootstrapper.java:104)
    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:65)
    ... 23 more

Coming from ( https://github.com/SonarSource/sonar-scanner-maven/blob/master/src/main/java/org/sonarsource/scanner/maven/bootstrap/MavenProjectConverter.java )

  private static void removeTarget(MavenProject pom, Collection<String> relativeOrAbsolutePaths) {
    final Path baseDir = pom.getBasedir().toPath().toAbsolutePath().normalize();
    final Path target = Paths.get(pom.getBuild().getDirectory()).toAbsolutePath().normalize();
    final Path targetRelativePath = baseDir.relativize(target);

    relativeOrAbsolutePaths.removeIf(pathStr -> {
      Path path = Paths.get(pathStr).toAbsolutePath().normalize();
      Path relativePath = baseDir.relativize(path);
      return relativePath.startsWith(targetRelativePath);
    });
  }

And Java relativize fct ( http://cr.openjdk.java.net/~alanb/6863864/webrev.00/src/windows/classes/sun/nio/fs/WindowsPath.java-.html ) :

@Override
 368     public WindowsPath relativize(Path obj) {
 369         WindowsPath other = checkPath(obj);
 370         if (this.equals(other))
 371             return null;
 372 
 373         // can only relativize paths of the same type
 374         if (this.type != other.type)
 375             throw new IllegalArgumentException("'other' is different type of Path");
 376 
 377         // can only relativize paths if root component matches
 378         if (!this.root.equalsIgnoreCase(other.root))
 379             throw new IllegalArgumentException("'other' has different root");

The Jenkins workspace is in the D:\ drive. This is most probably the cause of the problem.

When the same project,saved on the c:\ drive, is built on a local windows machine, no error is reported

Hi @Laurent_Peters,

First off; Happy new year!

Can you confirm if you are using symlinks or something similar?

Cheers,
Mark

Hi Mark,

Happy new year!

No, we are not using symlinks or something similar.

Regards,
Laurent

Hi @Laurent_Peters

Even though you are not using symlinks, or something similar, it does seem that you are effected by a limitation that also shows its face when using symlinks. For this we have an open ticket https://jira.sonarsource.com/browse/SONAR-14210 I would like to suggest that you watch that ticket to get updates as soon as we have found a solution for this and start development.

To be sure to set the appropriate expectations, this is a complex problem to solve that may need more time to find a proper solution. So please bare with us.

Cheers,
Mark

Hi @Laurent_Peters,

I have discussed this issue internally and I would like to request some more specific information on your build environment setup. This in an effort to reproduce the issue on our end.
Can you share as much detail of your build setup as possible? Especially your workspace setup in Jenkins. Are there any differences between where Jenkins executes the scan, the location of the maven src and target directories. The more details you can provide the higher the likelihood we can successfully attempt to reproduce the issue.

Cheers,
Mark

Hello,

Here are the locations of our tools, settings, workspace:

JAVA_HOME = C:\Program Files\Java\jdk1.8.0_221
MVN_CMD = d:\jenkins\tools\hudson.tasks.Maven_MavenInstallation\maven/bin/mvn.cmd)
WORKSPACE = d:\jenkins\workspace\xxxxx
MVNSETTINGS=c:\Users\ewonbuild_local.m2\settings.xml

The problem seems to be that some of these folders are in the c:\drive and others in the d:\drive.

Cheers,
Laurent