Replace usages of project.properties with gradleProperty()
Usages of project.properties is not allowed to support Gradle's configuration caching features.
RELNOTES=Fix an issue where Hilt's Gradle plugin was incompatible with Configuration Caching when `enableExperimentalClasspathAggregation` was turned ON.
PiperOrigin-RevId: 356553564
diff --git a/java/dagger/hilt/android/plugin/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt b/java/dagger/hilt/android/plugin/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt
index e26edb5..a82826e 100644
--- a/java/dagger/hilt/android/plugin/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt
+++ b/java/dagger/hilt/android/plugin/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt
@@ -32,10 +32,12 @@
import dagger.hilt.android.plugin.util.CopyTransform
import dagger.hilt.android.plugin.util.SimpleAGPVersion
import java.io.File
+import javax.inject.Inject
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
import org.gradle.api.attributes.Attribute
+import org.gradle.api.provider.ProviderFactory
/**
* A Gradle plugin that checks if the project is an Android project and if so, registers a
@@ -45,7 +47,9 @@
* classes annotated with `@AndroidEntryPoint` since the registered transform by this plugin will
* update the superclass.
*/
-class HiltGradlePlugin : Plugin<Project> {
+class HiltGradlePlugin @Inject constructor(
+ val providers: ProviderFactory
+) : Plugin<Project> {
override fun apply(project: Project) {
var configured = false
project.plugins.withType(AndroidBasePlugin::class.java) {
@@ -127,6 +131,7 @@
}
}
+ @Suppress("UnstableApiUsage")
private fun configureVariantCompileClasspath(
project: Project,
hiltExtension: HiltExtension,
@@ -160,7 +165,7 @@
"android.injected.build.model.only.versioned", // Sent by AS 2.4+
"android.injected.build.model.feature.full.dependencies", // Sent by AS 2.4+
"android.injected.build.model.v2", // Sent by AS 4.2+
- ).any { project.properties.containsKey(it) }
+ ).any { providers.gradleProperty(it).forUseAtConfigurationTime().isPresent }
) {
// Do not configure compile classpath when AndroidStudio is building the model (syncing)
// otherwise it will cause a freeze.
diff --git a/javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle b/javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle
index 43ccd1d..4f21d0a 100644
--- a/javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle
+++ b/javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle
@@ -38,6 +38,9 @@
kotlinOptions {
jvmTarget = '1.8'
}
+ lintOptions {
+ checkReleaseBuilds = false
+ }
testOptions {
unitTests.includeAndroidResources = true
}
@@ -45,6 +48,7 @@
hilt {
enableTransformForLocalTests = true
+ enableExperimentalClasspathAggregation = true
}
dependencies {