Home > other >  Kotlin 1.7 dependency resolution
Kotlin 1.7 dependency resolution

Time:10-21

Assume I have gradle mudule structure like that: module1 => module2 => gson. Module2 exposes gson as a return type in one of its public interfaces' methods but it's never used in module1. The dependencies are provided using

implementation

configuration. the question is should I provide gson dependency to module1 considering it's not used there or not? is there any standard for this? I'm asking because in kotlin 1.6.10 it works fine but kotlin 1.7.20 seems to break it and during dagger2 processing step I get an error like this:

ComponentProcessingStep was unable to process 'module1.MyComponent' because 'Gson' could not be resolved.

CodePudding user response:

This is what an api (instead of implementation) dependency is for in gradle. Just replace implementation("gson:...") with api("gson:...")

See https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation

So when should you use the api configuration? An API dependency is one that contains at least one type that is exposed in the library binary interface, often referred to as its ABI (Application Binary Interface). This includes, but is not limited to:

  • types used in super classes or interfaces
  • types used in public method parameters, including generic parameter types (where public is something that is visible to compilers. I.e. , public, protected and package private members in the Java world)
  • ...

The latter is your use case.

As for why dagger didn't complain in 1.6, I wouldn't know, in any case it was wrong in 1.6 as well, you just got lucky that nothing tripped over it.

  • Related