Skip to content

Commit

Permalink
Update Hilt Gradle Plugin to recognize hilt-compiler artifact.
Browse files Browse the repository at this point in the history
Update the dependency check the Hilt Gradle Plguin does to consider the
new coordinates of the Hilt compiler.

Fixes: #2086
RELNOTES=Update Hilt Gradle Plugin to recognize hilt-compiler artifact.
PiperOrigin-RevId: 330974190
  • Loading branch information
java-team-github-bot authored and Dagger Team committed Sep 10, 2020
1 parent fb47e11 commit 6e71d51
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ class HiltGradlePlugin : Plugin<Project> {
val dependencies = project.configurations.flatMap { configuration ->
configuration.dependencies.map { dependency -> dependency.group to dependency.name }
}
// TODO(user): Consider also validating Dagger compiler dependency.
listOf(
LIBRARY_GROUP to "hilt-android",
LIBRARY_GROUP to "hilt-android-compiler"
).filterNot { dependencies.contains(it) }.forEach { (groupId, artifactId) ->
error(
"The Hilt Android Gradle plugin is applied but no $groupId:$artifactId dependency " +
"was found."
)
if (!dependencies.contains(LIBRARY_GROUP to "hilt-android")) {
error(missingDepError("$LIBRARY_GROUP:hilt-android"))
}
if (!dependencies.contains(LIBRARY_GROUP to "hilt-android-compiler") &&
!dependencies.contains(LIBRARY_GROUP to "hilt-compiler")
) {
error(missingDepError("$LIBRARY_GROUP:hilt-compiler"))
}
}

Expand All @@ -110,5 +108,8 @@ class HiltGradlePlugin : Plugin<Project> {
"dagger.fastInit" to "enabled",
"dagger.hilt.android.internal.disableAndroidSuperclassValidation" to "true"
)
val missingDepError: (String) -> String = { depCoordinate ->
"The Hilt Android Gradle plugin is applied but no $depCoordinate dependency was found."
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class HiltGradlePluginTest {
gradleTransformRunner.addDependencies(
"implementation 'androidx.appcompat:appcompat:1.1.0'",
"implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'",
"annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'"
"annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'"
)
gradleTransformRunner.addActivities(
"<activity android:name=\".MainActivity\"/>"
Expand Down Expand Up @@ -105,7 +105,7 @@ class HiltGradlePluginTest {
gradleTransformRunner.addDependencies(
"implementation 'androidx.appcompat:appcompat:1.1.0'",
"implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'",
"annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'"
"annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'"
)

gradleTransformRunner.addSrc(
Expand Down Expand Up @@ -141,7 +141,7 @@ class HiltGradlePluginTest {
gradleTransformRunner.addDependencies(
"implementation 'androidx.appcompat:appcompat:1.1.0'",
"implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'",
"annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'"
"annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'"
)

gradleTransformRunner.addSrc(
Expand Down Expand Up @@ -177,7 +177,7 @@ class HiltGradlePluginTest {
gradleTransformRunner.addDependencies(
"implementation 'androidx.appcompat:appcompat:1.1.0'",
"implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'",
"annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'"
"annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'"
)

gradleTransformRunner.addSrc(
Expand Down Expand Up @@ -232,7 +232,7 @@ class HiltGradlePluginTest {
val result = gradleTransformRunner.buildAndFail()
assertThat(result.getOutput()).contains(
"The Hilt Android Gradle plugin is applied but no " +
"com.google.dagger:hilt-android-compiler dependency was found."
"com.google.dagger:hilt-compiler dependency was found."
)
}

Expand All @@ -242,7 +242,7 @@ class HiltGradlePluginTest {
gradleTransformRunner.addDependencies(
"implementation 'androidx.appcompat:appcompat:1.1.0'",
"implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'",
"annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'"
"annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'"
)

val srcFile = gradleTransformRunner.addSrc(
Expand Down Expand Up @@ -305,7 +305,7 @@ class HiltGradlePluginTest {
gradleTransformRunner.addDependencies(
"implementation 'androidx.appcompat:appcompat:1.1.0'",
"implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'",
"annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'"
"annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'"
)

gradleTransformRunner.addSrcPackage("ui/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class IncrementalProcessorTest {
implementation 'com.google.dagger:dagger:LOCAL-SNAPSHOT'
annotationProcessor 'com.google.dagger:dagger-compiler:LOCAL-SNAPSHOT'
implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'
annotationProcessor 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'
annotationProcessor 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'
}
""".trimIndent()
)
Expand Down
6 changes: 3 additions & 3 deletions javatests/artifacts/hilt-android/simple/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation project(':lib')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "com.google.dagger:hilt-android:$dagger_version"
annotationProcessor "com.google.dagger:hilt-android-compiler:$dagger_version"
annotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"

testImplementation 'com.google.truth:truth:1.0.1'
testImplementation 'junit:junit:4.13'
Expand All @@ -76,15 +76,15 @@ dependencies {
testImplementation 'androidx.test:runner:1.2.0'
testImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
testAnnotationProcessor "com.google.dagger:hilt-android-compiler:$dagger_version"
testAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"

androidTestImplementation 'com.google.truth:truth:1.0.1'
androidTestImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation "com.google.dagger:hilt-android-testing:$dagger_version"
androidTestAnnotationProcessor "com.google.dagger:hilt-android-compiler:$dagger_version"
androidTestAnnotationProcessor "com.google.dagger:hilt-compiler:$dagger_version"

// To help us catch usages of Guava APIs for Java 8 in the '-jre' variant.
annotationProcessor'com.google.guava:guava:28.1-android'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "com.google.dagger:hilt-android:$dagger_version"
kapt "com.google.dagger:hilt-android-compiler:$dagger_version"
kapt "com.google.dagger:hilt-compiler:$dagger_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'

implementation 'com.google.dagger:hilt-android:LOCAL-SNAPSHOT'
kapt 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'
kapt 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'

testImplementation 'com.google.truth:truth:1.0.1'
testImplementation 'junit:junit:4.13'
Expand All @@ -58,5 +58,5 @@ dependencies {
// TODO(bcorso): This multidex dep shouldn't be required -- it's a dep for the generated code.
testImplementation 'androidx.multidex:multidex:2.0.0'
testImplementation 'com.google.dagger:hilt-android-testing:LOCAL-SNAPSHOT'
kaptTest 'com.google.dagger:hilt-android-compiler:LOCAL-SNAPSHOT'
kaptTest 'com.google.dagger:hilt-compiler:LOCAL-SNAPSHOT'
}

0 comments on commit 6e71d51

Please sign in to comment.