I’m using SonarScanner Gradle plugin v4.2.1.3168, Gradle 8.1.1. I have configuration cache enabled via the org.gradle.unsafe.configuration-cache=true
flag in local.properties.
When I attempt to execute the following tasks:
./gradlew clean
./gradlew sonar
The execution fails with the following message:
Execution failed for task ':mylibrary:compileDebugAndroidTestKotlin'.
> Could not resolve all files for configuration ':mylibrary:debugAndroidTestCompileClasspath'.
> Failed to transform lib.jar (project :lib) to match attributes {artifactType=android-classes-jar, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.environment=standard-jvm, org.gradle.jvm.version=11, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for IdentityTransform: /Users/v_ermolin/Documents/Projects/SonarGradleIssue/lib/build/libs/lib.jar.
> File/directory does not exist: /Users/v_ermolin/Documents/Projects/SonarGradleIssue/lib/build/libs/lib.jar
The subsequent execution of ./gradlew sonar
passes. Notice, that it is important to not use chained tasks. I.e. ./gradlew clean sonar
works fine.
I first encountered this issue in a much complex environment on Bitbucket Pipelines CI. Then managed to narrow the issue down to the above. The minimal scope project, which mimics the setup of the real one and demonstrates the issue, is attached.
SonarGradleIssue.zip (6.5 MB)
I tried updating SonarScanner plugin to 4.4.1.3373 and Gradle to 8.5.0. Neither helped. Only disabling configuration cache addresses the issue.
I know that Sonar Plugin doesn’t support configuration cache. However, I’d expect it to not fail build in the above scenario, but only disable the cache.