Skip to content

Commit

Permalink
Add java-runtime usage attribute to the hiltCompileOnly configuration.
Browse files Browse the repository at this point in the history
Requesting org.gradle.usage attribute of value java-runtime can help dependency resolution disambiguate from a dependency whose variants all match the consuming attributes. This is somewhat rare but can happen in big projects where Java/Kotlin libraries and/or android libraries are forced to have a single build variant (i.e. no debug, just release) as done in the AndroidX repo.

RELNOTES=n/a
PiperOrigin-RevId: 379593791
  • Loading branch information
danysantiago authored and Dagger Team committed Jun 15, 2021
1 parent c513c01 commit 396be80
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ 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.attributes.Usage
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.tasks.compile.JavaCompile

Expand Down Expand Up @@ -308,6 +309,10 @@ class HiltGradlePlugin @Inject constructor(
isCanBeConsumed = false
isCanBeResolved = true
attributes { attrContainer ->
attrContainer.attribute(
Usage.USAGE_ATTRIBUTE,
project.objects.named(Usage::class.java, Usage.JAVA_RUNTIME)
)
attrContainer.attribute(
BuildTypeAttr.ATTRIBUTE,
project.objects.named(BuildTypeAttr::class.java, variant.buildType.name)
Expand Down

0 comments on commit 396be80

Please sign in to comment.