Skip to content

Commit ad682e5

Browse files
authored
build(gradle): enable configuration cache, drop configuration-on-demand (#972)
* build(gradle): enable configuration cache, drop configuration-on-demand Turn on org.gradle.configuration-cache and remove the now-superseded org.gradle.configureondemand (configuration-on-demand is incompatible with the configuration cache). Builds on the cross-project config removal from #971, which cleared the root-script barriers to a cacheable configuration phase. Validated locally: full configuration of all modules succeeds with zero configuration-cache problems, the entry is reused across runs, and a module unit test executes and reuses the cache. Problems fail the build by default, so CI enforces a clean configuration phase. This is also the prerequisite for enabling Isolated Projects later. * build(gradle): make root-dir access Isolated Projects-safe Replace cross-project root access that Isolated Projects forbids with the IP-safe equivalents, without changing behavior: - compose convention plugin & app: rootProject.layout.projectDirectory -> isolated.rootProject.projectDirectory for the stability config file. - ContributorsSignatory: take the root directory as a File instead of a Project, so callers no longer invoke Project.file on the root project. Path resolution is unchanged (relative against root, absolute as-is). Verified under the configuration cache (already enabled): full configuration succeeds with zero problems and the entry reuses cleanly. With these in place, flipping org.gradle.unsafe.isolated-projects drops from 356 problems to a single remaining AGP-internal access in com.android.application, which is upstream and will clear with a future AGP that fully supports Isolated Projects. The IP flag stays off until then.
1 parent f42107f commit ad682e5

5 files changed

Lines changed: 30 additions & 20 deletions

File tree

apps/flipcash/app/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fun gitVersionCode(): Int {
2424
return result.toInt().also { println("VersionCode $it") }
2525
}
2626

27-
val contributorsSigningConfig = ContributorsSignatory(rootProject)
27+
val contributorsSigningConfig = ContributorsSignatory(rootDir)
2828
val appNamespace = "${Gradle.flipcashNamespace}.app.android"
2929

3030
android {
@@ -125,8 +125,9 @@ bugsnag {
125125
}
126126

127127
composeCompiler {
128+
// Isolated Projects-safe root access (see AndroidLibraryComposeConventionPlugin).
128129
stabilityConfigurationFile.set(
129-
rootProject.layout.projectDirectory.file("compose_compiler_config.conf")
130+
isolated.rootProject.projectDirectory.file("compose_compiler_config.conf")
130131
)
131132
}
132133

apps/flipcash/benchmark/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
id("com.android.test")
33
}
44

5-
val contributorsSigningConfig = ContributorsSignatory(rootProject)
5+
val contributorsSigningConfig = ContributorsSignatory(rootDir)
66

77
android {
88
namespace = "com.flipcash.benchmark"

build-logic/convention/src/main/kotlin/AndroidLibraryComposeConventionPlugin.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ class AndroidLibraryComposeConventionPlugin : Plugin<Project> {
2222
}
2323

2424
extensions.configure<ComposeCompilerGradlePluginExtension> {
25+
// Use the Isolated Projects-safe accessor for the root directory.
26+
// `rootProject.layout` reaches into another project's model, which
27+
// Isolated Projects forbids; `isolated.rootProject` is the blessed
28+
// read-only view that exposes the root project directory safely.
2529
stabilityConfigurationFile.set(
26-
rootProject.layout.projectDirectory.file("compose_compiler_config.conf")
30+
isolated.rootProject.projectDirectory.file("compose_compiler_config.conf")
2731
)
2832
}
2933

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import org.gradle.api.Project
1+
import java.io.File
22
import java.util.Properties
33

4-
5-
class ContributorsSignatory(project: Project) {
6-
private val signingProperties: Properties
7-
8-
init {
9-
val propertiesFile = project.file("contributors.properties")
10-
signingProperties = Properties().apply {
11-
load(propertiesFile.inputStream())
12-
}
4+
/**
5+
* Reads the contributor signing config from `contributors.properties` at the
6+
* given [rootDir].
7+
*
8+
* Takes the root directory as a [File] rather than a [org.gradle.api.Project] so
9+
* callers don't reach into another project (`rootProject.file(...)`), which
10+
* Isolated Projects forbids. Paths resolve as `Project.file` did: relative
11+
* entries against [rootDir], absolute entries as-is.
12+
*/
13+
class ContributorsSignatory(rootDir: File) {
14+
private val signingProperties: Properties = Properties().apply {
15+
rootDir.resolve("contributors.properties").inputStream().use { load(it) }
1316
}
1417

15-
val keystore = project.file(signingProperties.getProperty("KEYSTORE_FILE"))
18+
val keystore: File = rootDir.resolve(signingProperties.getProperty("KEYSTORE_FILE"))
1619
val keystorePassword: String = signingProperties.getProperty("KEYSTORE_PASS")
1720
val keyAlias: String = signingProperties.getProperty("KEY_ALIAS")
1821
val keyPassword: String = signingProperties.getProperty("KEY_PASS")
19-
}
22+
}

gradle.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ org.gradle.parallel=true
1515
# Improves build performance by avoiding redundant task execution
1616
# More details: https://docs.gradle.org/current/userguide/build_cache.html
1717
org.gradle.caching=true
18-
# Enables configuration on demand, making Gradle configure only necessary projects
19-
# Speeds up builds in multi-project setups by skipping unneeded configurations
20-
# More details: https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:configuration_on_demand
21-
org.gradle.configureondemand=true
18+
# Enables the configuration cache: caches the result of the configuration phase
19+
# and reuses it across builds, configuring projects in parallel and in isolation.
20+
# This supersedes configuration-on-demand (which is incompatible with it).
21+
# Problems fail the build by default, so CI enforces a clean configuration phase.
22+
# More details: https://docs.gradle.org/current/userguide/configuration_cache.html
23+
org.gradle.configuration-cache=true
2224
# AndroidX package structure to make it clearer which packages are bundled with the
2325
# Android operating system, and which are packaged with your app"s APK
2426
# https://developer.android.com/topic/libraries/support-library/androidx-rn

0 commit comments

Comments
 (0)