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:
![Screen Shot 2024-01-24 at 1 46 04 PM](https://private-user-images.githubusercontent.com/11139192/299468365-ccd2032d-cafb-40fe-9c6e-58f49cc71bf6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTgwMDI1MTQsIm5iZiI6MTcxODAwMjIxNCwicGF0aCI6Ii8xMTEzOTE5Mi8yOTk0NjgzNjUtY2NkMjAzMmQtY2FmYi00MGZlLTljNmUtNThmNDljYzcxYmY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjEwVDA2NTAxNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ3MzZhZjgzYjVjNjc5MjZhYTRiOTg0YzFkMDU4ZTVhNmI2YTg2YWEwYzBhNmE3OTBmMGU5ZWZjMmFmZTczODcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6lff_Sx7tvFTMKmgzPfUplOLaK8a_cnmRB2kIUpZw2c)
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.