0

I have a project A which depends on library B, I am using gradle composite builds.

Project B contains several common dependencies such as "org.apache.commons:commons-lang3"

Project A uses "org.apache.commons:commons-lang3" as well but transitive dependencies resolution does not work as I would expect, I have to declare again "org.apache.commons:commons-lang3" in the dependencies block of project A build.gradle in order to make it work.

Project A build.gradle:

group = 'org.example.app'
version = '0.1.0'

plugins {
   id 'java'
   id 'application' 
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

dependencies {
    implementation 'org.example.libs:B'
}

Project A settings.gradle

includeBuild '../../libs/B'

Project B build.gradle:

group = 'org.example.libs'
version = '0.1.0

plugins {
   id 'java-library'
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

dependencies {
    implementation 'org.apache.commons:commons-lang3:3.12.0'
}

repositories {
    mavenCentral()
}

Project B compiles well as standalone but I can't compile project A without adding again "org.apache.commons:commons-lang3:3.12.0" in its build.gradle. Isn't it supposed to be resolved as transitive dependency from project B ?

Project A Compilation throws errors such as :

error: package org.apache.commons.lang3 does not exist

What am I missing ?

0wn3r
  • 103
  • 4

1 Answers1

1

This probably has been answered many times, but I cannot find a good answer.

To make transitive dependencies available, you have to use api rather than implementation in project B.

dependencies {
    api 'org.apache.commons:commons-lang3:3.12.0'
}

If you have previous experience with maven, you'll need to unlearn a lot of stuff as gradle is a very different beast and reading the manual is well worth it (even if it's a bit tedious)

Augusto
  • 28,839
  • 5
  • 58
  • 88