Hi, it seems maven-shade-plugin when upgraded from (working) 3.2.4
to (breaking) 3.5.3
will change the maven property ${project.baseDir}
. I don’t know if this is a bug in shade or sonar.
The result is that sonar scanner runs from inside the target
folder as its project base dir, and finds no source files nor coverage.
Explicitly setting <sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
makes no difference. That’s why I think shade is overwriting this value.
Logs from shade 3.2.4:
2024-04-26T12:09:22.0978416Z [INFO] 12:09:22.097 Base dir: /home/runner/work/my-private-project/my-private-project
Logs from shade 3.5.3:
2024-04-26T11:41:18.0620501Z [INFO] 11:41:18.061 Base dir: /home/runner/work/my-private-project/my-private-project/target
-
GitHub
-
Github Actions
-
Kotlin
-
Potential workaround: downgrade shade
maven pom.xml snippets:
<profile>
<id>sonarcloud</id>
<activation>
<property>
<name>env.SONARCLOUD_TOKEN</name>
</property>
</activation>
<properties>
<sonar.organization>my-org-here</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.projectKey>redacted</sonar.projectKey>
<sonar.token>${env.SONARCLOUD_TOKEN}</sonar.token>
<sonar.projectBaseDir>${project.basedir}</sonar.projectBaseDir>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.11.0.3922</version>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sonar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
shade
<maven-shade-plugin.version>3.5.3</maven-shade-plugin.version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml
</dependencyReducedPomLocation>
<filters>
<!-- Excluding signed manifest files from dependencies -->
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
All shade versions from 3.3.0 (2022-03-24) and after will have this issue. The latest working shade is 3.2.4.
To see if basedir is changed for every plugin, I ran a stat
together with shade 3.5.3 , and no, basedir is correct here: /home/runner/work/my-private-project/my-private-project
. This runs just before sonar, when I inspect logs.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>exec-stat</id>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>stat</executable>
<arguments>
<argument>${project.basedir}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>