Miles Peele
10/15/2024, 1:52 PM--build-cache to my GradleRunner invocation and having org.gradle.caching=true in the project's gradle.properties, but I always get this console output from my test:
Caching disabled for Kotlin DSL script compilation (Settings/TopLevel/stage2) because:
Build cache is disabled
I can share more in the below thread, just wanted to make sure I'm not missing something obvious/not aware of something new the docs haven't specified?
Using org.gradle.caching=true in my root project's gradle.properties file seems to work just fineMiles Peele
10/15/2024, 1:55 PMTemporaryFolder to create directories for each shim Project. I'm creating a gradle.properties file directly under that temp folder (where the root project is) to pass org.gradle.caching=true.
I have a test that this is compatible with the configuration cache that passes (fancy APIs are fairly simple in their impl):
@Test
fun `should be configuration-cacheable`() {
root.enableConfigurationCache()
androidApp.dependency(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, HAMCREST_DEPENDENCY_NAME)
androidLib.dependency(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, HAMCREST_DEPENDENCY_NAME)
javaLib.dependency(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, HAMCREST_DEPENDENCY_NAME)
@Suppress("UNUSED_VARIABLE")
val firstBuildResult = root.run(CheckTestDependencyLeak.NAME)
val secondBuildResult = root.run(CheckTestDependencyLeak.NAME)
secondBuildResult.assertUsingConfigurationCache()
}
But this fails:
@Test
fun `should be cacheable`() {
root.enableBuildCache()
androidApp.dependency(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, HAMCREST_DEPENDENCY_NAME)
androidLib.dependency(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, HAMCREST_DEPENDENCY_NAME)
javaLib.dependency(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, HAMCREST_DEPENDENCY_NAME)
@Suppress("UNUSED_VARIABLE")
val firstBuildResult = root.run(CheckTestDependencyLeak.NAME).printOutput()
androidApp.deleteBuildDir()
androidLib.deleteBuildDir()
javaLib.deleteBuildDir()
val secondBuildResult = root.run(CheckTestDependencyLeak.NAME).printOutput()
secondBuildResult.assertCached(":app:${CheckTestDependencyLeak.NAME}")
secondBuildResult.assertCached(":javaLib:${CheckTestDependencyLeak.NAME}")
secondBuildResult.assertCached(":androidLib:${CheckTestDependencyLeak.NAME}")
}Miles Peele
10/15/2024, 1:56 PMenable* methods:
fun enableBuildCache() {
gradleProperty("org.gradle.caching", true)
}
fun enableConfigurationCache() {
gradleProperty("org.gradle.configuration-cache", true)
}
Those will eventually write down to gradle.propertiesMiles Peele
10/15/2024, 2:04 PMbuild cache is disabled message - I get a UP-TO-DATE instead of a FROM-CACHE outcomeAnze Sodja
10/15/2024, 2:14 PMCaching disabled for Kotlin DSL script compilation (Settings/TopLevel/stage2) because:
Build cache is disabled
is a message for compilation of settings.gradle.kts . You probably should ignore it. Build cache is not ready yet when settings.gradle.kts is compiled, since it's configured in the settings.gradle.kts . Message Build cache is disabled is a bit unfortunate in that case.Thomas Broyer
10/15/2024, 2:15 PMMiles Peele
10/15/2024, 2:15 PMMiles Peele
10/15/2024, 2:16 PMIs it really because of "build cache is disabled"?That was my assumption from the messaging, but if that's a bad signal then there's something wrong with my cacheable-task attempt
Anze Sodja
10/15/2024, 2:22 PMSo it is enabled, the messaging there is just a bit unfortunate?Message in that case should say something like:
Build cache is not ready yet
You should check a message for a task you are testing, to get better information if it is cached or notAnze Sodja
10/15/2024, 2:23 PM:help with --info
Caching disabled for task ':help' because:
Produces only non-cacheable console outputThomas Broyer
10/15/2024, 2:29 PMIn a test I wrote, I delete the build dir in between runs.Did you try that? (not necessarily to keep it in the end, but at least to test if it gives a different outcome)
Miles Peele
10/15/2024, 2:35 PMandroidApp.deleteBuildDir()
androidLib.deleteBuildDir()Thomas Broyer
10/15/2024, 2:38 PMMiles Peele
10/15/2024, 3:01 PM