How do I control whether a dependency is re-exported?


(Kannan Goundan) #1

Lets say I’m writing a library called “twitter-api-client” and my library two other libraries – Google’s Guava collections library and Apache’s httpclient library. In my Gradle file, I specify those two as dependencies. However, those two dependencies are slightly different.

The Google Guava class names appear in my public API, so anyone using my library has to also import Google Guava (compile-time and runtime dependency for me and any projects that use me).

On the other hand, I use Apache’s httpclient internally. Someone using my library doesn’t have to even know that I use that library (compile-time dependency for my project, but only a runtime dependency for projects that use my library).

Because of this difference, it would be convenient if I could specify that anyone who depends on my library automatically gets a compile-time dependency for the Google Guava library, but only a runtime dependency on the Apache httpclient library. Is there a way to do this? Does this have anything to do with the “transitive” setting on a dependency?

(Relatedly, what exactly does “transitive” mean for a dependency? The documentation is a little abstract in that area.)