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