Stack Exchange
Gradle 4.x API instead of implementation - How can i use gradle API feature to expose internal dependencies
I'm using gradle 4.x and here is my problem.
I've two modules A and B.
Module B has project dependency on module A. Here are the gradle files.
build.gradle for module A
apply plugin: 'java-library'

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter'
    implementation group: 'org.springframework.kafka', name: 'spring-kafka' , version: '2.2.7.RELEASE'
    implementation group: 'org.springframework.cloud', name: 'spring-cloud-spring-service-connector'
    implementation group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector'

    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
    testImplementation group: 'io.github.benas', name: 'random-beans', version: '3.7.0'
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

Here is the build.gradle for module B
dependencies {
    implementation project(':moduleA')

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter'
    implementation group: 'org.springframework.kafka', name: 'spring-kafka' , version: '2.2.7.RELEASE'
    implementation group: 'org.springframework.cloud', name: 'spring-cloud-spring-service-connector'
    implementation group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector'

    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
    testImplementation group: 'io.github.benas', name: 'random-beans', version: '3.7.0' }

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}

If you observe the build.gradle file for module B, i've a dependency for spring-kafka but it's a duplicate since it's already in module A build.gradle.
Now how can use gradle API option to expose spring-kafka (from module A) without actually mentioning it in module B's build.gradle when the jar file of module B is being consumed by another app?
Please suggest.

This is explained in the docs here (emphasis mine):

The plugin exposes two configurations that can be used to declare dependencies: api and implementation. The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.

So simply change implementation to api in moduleA:
api group: 'org.springframework.kafka', name: 'spring-kafka' , version: '2.2.7.RELEASE'

Then remove the entry from moduleB's Gradle file.
