From b25eab8970c29ff987748aed9268cd75b78b26cb Mon Sep 17 00:00:00 2001 From: Daniel Santiago Date: Tue, 9 Feb 2021 11:42:45 -0800 Subject: [PATCH] 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 --- .../dagger/hilt/android/plugin/HiltGradlePlugin.kt | 9 +++++++-- .../hilt-android/gradleConfigCache/app/build.gradle | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) 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 e26edb5fde3..a82826ed812 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 com.android.build.gradle.api.UnitTestVariant 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 @@ import org.gradle.api.attributes.Attribute * classes annotated with `@AndroidEntryPoint` since the registered transform by this plugin will * update the superclass. */ -class HiltGradlePlugin : Plugin { +class HiltGradlePlugin @Inject constructor( + val providers: ProviderFactory +) : Plugin { override fun apply(project: Project) { var configured = false project.plugins.withType(AndroidBasePlugin::class.java) { @@ -127,6 +131,7 @@ class HiltGradlePlugin : Plugin { } } + @Suppress("UnstableApiUsage") private fun configureVariantCompileClasspath( project: Project, hiltExtension: HiltExtension, @@ -160,7 +165,7 @@ class HiltGradlePlugin : Plugin { "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 43ccd1d55ba..4f21d0a38d9 100644 --- a/javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle +++ b/javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle @@ -38,6 +38,9 @@ android { kotlinOptions { jvmTarget = '1.8' } + lintOptions { + checkReleaseBuilds = false + } testOptions { unitTests.includeAndroidResources = true } @@ -45,6 +48,7 @@ android { hilt { enableTransformForLocalTests = true + enableExperimentalClasspathAggregation = true } dependencies {