Skip to content

Commit

Permalink
Mark enableTransformForLocalTests from the Gradle plugin options as…
Browse files Browse the repository at this point in the history
… deprecated.

With the minimum AGP required to be 7.0 the option is no longer relevant and its code path has been removed.

Also added a bit more documentation to the other options.

RELNOTES=Deprecate the `enableTransformForLocalTests` in the Hilt Android Gradle plugin.
PiperOrigin-RevId: 544721475
  • Loading branch information
danysantiago authored and Dagger Team committed Jun 30, 2023
1 parent ebeaaf7 commit b3fd56f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ interface HiltExtension {
* If set to `true`, Hilt will adjust the compile classpath such that it includes transitive
* dependencies, ignoring `api` or `implementation` boundaries during compilation. You should
* enable this option if your project has multiple level of transitive dependencies that contain
* injected classes or entry points.
* injected classes or entry points. The default value is `false`.
*
* Enabling this option also requires android.lintOptions.checkReleaseBuilds to be set to 'false'
* if the Android Gradle Plugin version being used is less than 7.0.
* This option should be enable as a last resort to avoid classpath issues if
* [enableAggregatingTask] (set to `true` by default) causes issues.
*
* See https://github.com/google/dagger/issues/1991 for more context.
*/
Expand All @@ -37,22 +37,26 @@ interface HiltExtension {
* annotated classes before the host-side JVM tests run. You should enable this option if you are
* running Robolectric UI tests as part of your JUnit tests.
*
* This flag is not necessary if when com.android.tools.build:gradle:4.2.0+ is used and will be
* deprecated in a future version.
* This flag is not necessary when com.android.tools.build:gradle:4.2.0+ is used.
*/
@Deprecated("Since Hilt Android Gradle plugin requires the usage of the Android " +
"Gradle plugin (AGP) version 7.0 or higher this option is no longer necessary and has no " +
"effect in the configuration.")
var enableTransformForLocalTests: Boolean

/**
* If set to `true`, Hilt will perform module and entry points aggregation in a task instead of an
* aggregating annotation processor. Enabling this flag improves incremental build times.
* aggregating annotation processor. Enabling this flag improves incremental build times. The
* default value is `true`.
*
* When this flag is enabled, 'enableExperimentalClasspathAggregation' has no effect since
* classpath aggregation will be done by default.
* classpath aggregation is already performed by the aggregation task.
*/
var enableAggregatingTask: Boolean

/**
* If set to `true`, Hilt will disable cross compilation root validation.
* If set to `true`, Hilt will disable cross compilation root validation. The default value is
* `false`.
*
* See [documentation](https://dagger.dev/hilt/flags#disable-cross-compilation-root-validation)
* for more information.
Expand All @@ -62,6 +66,9 @@ interface HiltExtension {

internal open class HiltExtensionImpl : HiltExtension {
override var enableExperimentalClasspathAggregation: Boolean = false
@Deprecated("Since Hilt Android Gradle plugin requires the usage of the Android " +
"Gradle plugin (AGP) version 7.0 or higher this option is no longer necessary and has no " +
"effect in the configuration.")
override var enableTransformForLocalTests: Boolean = false
override var enableAggregatingTask: Boolean = true
override var disableCrossCompilationRootValidation: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HiltGradlePlugin @Inject constructor(
}
configureDependencyTransforms(project)
configureCompileClasspath(project, hiltExtension)
configureBytecodeTransformASM(project, hiltExtension)
configureBytecodeTransformASM(project)
configureAggregatingTask(project, hiltExtension)
configureProcessorFlags(project, hiltExtension)
}
Expand Down Expand Up @@ -241,16 +241,8 @@ class HiltGradlePlugin @Inject constructor(
project.dependencies.add(compileOnlyConfigName, artifactView.files)
}

private fun configureBytecodeTransformASM(project: Project, hiltExtension: HiltExtension) {
var warnAboutLocalTestsFlag = false
private fun configureBytecodeTransformASM(project: Project) {
fun registerTransform(androidComponent: ComponentCompat) {
if (hiltExtension.enableTransformForLocalTests && !warnAboutLocalTestsFlag) {
project.logger.warn(
"The Hilt configuration option 'enableTransformForLocalTests' is no longer necessary " +
"when com.android.tools.build:gradle:4.2.0+ is used."
)
warnAboutLocalTestsFlag = true
}
androidComponent.transformClassesWith(
classVisitorFactoryImplClass = AndroidEntryPointClassVisitor.Factory::class.java,
scope = InstrumentationScope.PROJECT
Expand Down Expand Up @@ -466,29 +458,27 @@ class HiltGradlePlugin @Inject constructor(
.flatMap { configuration ->
configuration.dependencies.map { dependency -> dependency.group to dependency.name }
}.toSet()
fun getMissingDepMsg(depCoordinate: String): String =
"The Hilt Android Gradle plugin is applied but no $depCoordinate dependency was found."
if (!dependencies.contains(LIBRARY_GROUP to "hilt-android")) {
error(missingDepError("$LIBRARY_GROUP:hilt-android"))
error(getMissingDepMsg("$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"))
error(getMissingDepMsg("$LIBRARY_GROUP:hilt-compiler"))
}
}

private fun Project.baseExtension(): BaseExtension?
= extensions.findByType(BaseExtension::class.java)

companion object {
val ARTIFACT_TYPE_ATTRIBUTE = Attribute.of("artifactType", String::class.java)
private val ARTIFACT_TYPE_ATTRIBUTE = Attribute.of("artifactType", String::class.java)
const val DAGGER_ARTIFACT_TYPE_VALUE = "jar-for-dagger"
const val AGGREGATED_HILT_ARTIFACT_TYPE_VALUE = "aggregated-jar-for-hilt"

const val LIBRARY_GROUP = "com.google.dagger"

val missingDepError: (String) -> String = { depCoordinate ->
"The Hilt Android Gradle plugin is applied but no $depCoordinate dependency was found."
}
}
}

0 comments on commit b3fd56f

Please sign in to comment.