Plugin version
2.1.6
(latest)
Gradle version
8.0.2
JDK version
17
(Optional) Kotlin and Kotlin Gradle Plugin (KGP) version
1.9.20
(Optional) Android Gradle Plugin (AGP) version
8.1.1
Describe the bug
We have a weekly job that runs Gradle's Cache Validation Scripts to verify our project is not executing any cacheable tasks during incremental builds with no changes.
One of the scripts, 03-validate-local-build-caching-different-locations.sh
, verifies that caching does not break if a project is built from different locations (i.e. different directories).
For example, say we've cloned the same project, Example-App
, in two different directories:
path/to/project/first/Example-App
path/to/project/second/Example-App
If we run a build from path/to/project/first/Example-App
, and then we run a second build from path/to/project/second/Example-App
with no changes on the same branch, the second build should reuse the cached output for cacheable tasks from the first build because the cached output for both builds is hosted in ~/.gradle/caches/build-cache-1/
.
The experiment reported numerous, 41, cacheable tasks executed in the second build. If everything is working properly, this number should be 0. We examined the executed cacheable tasks and found, all of them were of type com.google.devtools.ksp.gradle.KspTaskJvm
.
To help diagnose the issue, we compared build scans for these two builds to determine what changed in the second build:
input 'pluginOptions.$0.asTaskInputArgs' is in both builds but the values are different.
In order to determine what changed, we added the following to our root build.gradle
:
tasks.withType(com.google.devtools.ksp.gradle.KspTaskJvm).configureEach {
doLast {
pluginOptions.get().forEach { compilerPluginConfig ->
compilerPluginConfig.getAsTaskInputArgs().findAll { entry ->
rootProject.buildScan.value(
"${entry.key}", entry.value,
)
}
}
}
}
We reran the experiment and found that the inputs for com.google.devtools.ksp.gradle.KspTaskJvm
changed from:
- [1] emerge.outputDir=/opt/workdir/gradle-enterprise-gradle-build-validation/.data/03-validate-local-build-caching-different-locations/20240124T184213-65b15a05/first-build_workdir/Example-App/build/emergetools/ksp/debugAndroidTest/kotlin
- [2] emerge.outputDir=/opt/workdir/gradle-enterprise-gradle-build-validation/.data/03-validate-local-build-caching-different-locations/20240124T184213-65b15a05/second-build_workdir/Example-App/build/emergetools/ksp/debugAndroidTest/kotlin
Essentially, the value of emerge.outputDir
is different in both builds.
The implications of this is that we can't reuse the output of :<project>:kspDebugKotlin
, leading to slower builds.
We suspect this line to be the culprit:
|
val emergeSrcDir = "${project.buildDir}/$BUILD_OUTPUT_DIR_NAME/ksp/debugAndroidTest/kotlin" |
To Reproduce
Steps to reproduce the behavior:
- Clone a project in different locations
- Run a build in one project
- Run a build, on the same branch, no code change, from the different project location with build scan
- Observe if any cacheable tasks were executed in the second build
Expected behavior
The outputs of the first build should be reused in the second build. The inputs to the plugin should be the same.