Java-library plugin: why are api dependencies exported transitively?


(Andi) #1

Reading the documentation of the java-library plugin I wonder why api dependencies appear transitively on the consumers compile classpath?

Looking at the given example a consumer would be able to use classes of commons-codec (because its a dependency of commons-httpclient) although none of them appear in the ABI of HttpClientWrapper.

So why not make api dependencies transitive = false by default, so that java-library projects don’t have to define api dependencies twice to get a clean solution?

dependencies {
// commons-httpclient has a dependency on commons-codec.
// None of the commons-codec classes are in ABI of HttpClientWrapper so
// there is no reason to have those on the compile classpath of consumers
api(‘commons-httpclient:commons-httpclient:3.1’) { transitive = false }
runtimeOnly(‘commons-httpclient:commons-httpclient:3.1’)
implementation ‘org.apache.commons:commons-lang3:3.5’
}


(Andi) #2

Maybe @Rene can shed some light on this?


(Andi) #3

This is actually a bug see Issue 977