Skip to content

Commit

Permalink
Replace usages of project.properties with gradleProperty()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
danysantiago authored and Dagger Team committed Feb 9, 2021
1 parent 438bb1d commit b25eab8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Project> {
class HiltGradlePlugin @Inject constructor(
val providers: ProviderFactory
) : Plugin<Project> {
override fun apply(project: Project) {
var configured = false
project.plugins.withType(AndroidBasePlugin::class.java) {
Expand Down Expand Up @@ -127,6 +131,7 @@ class HiltGradlePlugin : Plugin<Project> {
}
}

@Suppress("UnstableApiUsage")
private fun configureVariantCompileClasspath(
project: Project,
hiltExtension: HiltExtension,
Expand Down Expand Up @@ -160,7 +165,7 @@ class HiltGradlePlugin : Plugin<Project> {
"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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
lintOptions {
checkReleaseBuilds = false
}
testOptions {
unitTests.includeAndroidResources = true
}
}

hilt {
enableTransformForLocalTests = true
enableExperimentalClasspathAggregation = true
}

dependencies {
Expand Down

0 comments on commit b25eab8

Please sign in to comment.