google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.42k stars 2.01k forks source link

Unable to use `@TestInstallIn` in java-library module since it's a part of Android artifact (aar) #3196

Open plnice opened 2 years ago

plnice commented 2 years ago

In my Android project I have a Gradle java-library module which I use to provide a utility class that doesn't need a dependency on Android SDK. The module contains the interface for the utility, internal implementation class and the Hilt module with @InstallIn(SingletonComponent::class) annotation that binds the implementation to the interface; it has dependency on hilt-core java-only artifact.

What I want to do is to add testFixtures source set to the module and within it create test implementation and test module annotated with @TestInstallIn. However, @TestInstallIn annotation is provided as a part of hilt-android-testing artifact, which is an Android artifact (aar). Therefore I cannot attach it to the java-library project.

What I'd expect is to have another dependency, let's say hilt-core-testing, that only provides the @TestInstallIn annotation, and the dependency is served as a jar.

kelmer44 commented 5 months ago

this would be a great addition