Java-library "implementation" dependencies


(Jesper Blomquist) #1

According to chapter 48.2 “API and implementation separation”;

dependencies do not leak into the compile classpath of consumers anymore, so you will never accidently depend on a transitive dependency

How am I supposed to declare my dependency as a consumer to make this true?

My setup:
lib (with java-library plugin)

dependencies {
    implementation project(':reactivestreams-utils')
    implementation 'com.google.guava:guava:21.0'
    api "org.reactivestreams:reactive-streams:$reactiveStreamsVersion"
    api 'com.netflix.hystrix:hystrix-core:1.5.12'
}

consumer (with java plugin)

dependencies {
    compile '<lib>'
}

AFAIK this will make the default resource set part of the consumers compile resource set. Hence including runtime dependencies, and voilà, behold the guts of my library :frowning:


(Stefan Oehme) #2

It doesn’t matter which Configuration (compile, compileOnly, api, implementation) the consumer uses, it will not see the implementation details of the library.

You can also use the implementation Configuration in the java plugin btw.


(Jesper Blomquist) #3

My experience from earlier today tells a different story. They are visible on the compile classpath.
I deploy to a maven repo (in the pom, the deps have “runtime” scope). I also resolve the dependency in my service from the same maven repo…


(Stefan Oehme) #4

Variant aware dependency management does not yet work with external dependencies, only with project dependencies. See this issue.


(Jesper Blomquist) #5

Ok, thanks :thumbsup: