Skip to content

Commit b25eab8

Browse files
danysantiagoDagger Team
authored andcommitted
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
1 parent 438bb1d commit b25eab8

File tree

2 files changed

+11
-2
lines changed
  • javatests/artifacts/hilt-android/gradleConfigCache/app
  • java/dagger/hilt/android/plugin/src/main/kotlin/dagger/hilt/android/plugin

2 files changed

+11
-2
lines changed

java/dagger/hilt/android/plugin/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import com.android.build.gradle.api.UnitTestVariant
3232
import dagger.hilt.android.plugin.util.CopyTransform
3333
import dagger.hilt.android.plugin.util.SimpleAGPVersion
3434
import java.io.File
35+
import javax.inject.Inject
3536
import org.gradle.api.Plugin
3637
import org.gradle.api.Project
3738
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
3839
import org.gradle.api.attributes.Attribute
40+
import org.gradle.api.provider.ProviderFactory
3941

4042
/**
4143
* 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
4547
* classes annotated with `@AndroidEntryPoint` since the registered transform by this plugin will
4648
* update the superclass.
4749
*/
48-
class HiltGradlePlugin : Plugin<Project> {
50+
class HiltGradlePlugin @Inject constructor(
51+
val providers: ProviderFactory
52+
) : Plugin<Project> {
4953
override fun apply(project: Project) {
5054
var configured = false
5155
project.plugins.withType(AndroidBasePlugin::class.java) {
@@ -127,6 +131,7 @@ class HiltGradlePlugin : Plugin<Project> {
127131
}
128132
}
129133

134+
@Suppress("UnstableApiUsage")
130135
private fun configureVariantCompileClasspath(
131136
project: Project,
132137
hiltExtension: HiltExtension,
@@ -160,7 +165,7 @@ class HiltGradlePlugin : Plugin<Project> {
160165
"android.injected.build.model.only.versioned", // Sent by AS 2.4+
161166
"android.injected.build.model.feature.full.dependencies", // Sent by AS 2.4+
162167
"android.injected.build.model.v2", // Sent by AS 4.2+
163-
).any { project.properties.containsKey(it) }
168+
).any { providers.gradleProperty(it).forUseAtConfigurationTime().isPresent }
164169
) {
165170
// Do not configure compile classpath when AndroidStudio is building the model (syncing)
166171
// otherwise it will cause a freeze.

javatests/artifacts/hilt-android/gradleConfigCache/app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ android {
3838
kotlinOptions {
3939
jvmTarget = '1.8'
4040
}
41+
lintOptions {
42+
checkReleaseBuilds = false
43+
}
4144
testOptions {
4245
unitTests.includeAndroidResources = true
4346
}
4447
}
4548

4649
hilt {
4750
enableTransformForLocalTests = true
51+
enableExperimentalClasspathAggregation = true
4852
}
4953

5054
dependencies {

0 commit comments

Comments
 (0)