Having the following multi-module-setup:
multi
├── projA
│ └── build.gradle.kts
├── projB
│ └── build.gradle.kts
├── build.gradle.kts
└── settings.gradle.kts
with the following content (abbreviated):
settings.gradle.kts
rootProject.name = "multi"
include("projA", "projB")
projA\build.gradle.kts
dependencies {
implementation("important-library:1.0")
}
projB\build.gradle.kts
dependencies {
implementation(project(":projA"))
}
Why don't I have access to that importantlibrary:1.0
from projB
?
What works: if I have a class within projA
that uses the library, it works perfectly even if that class is called from a class within projB
(so indirect access works). Directly accessing any class from importantlibrary:1.0
within projB
doesn't work (unresolved reference).
What am I missing here? Or what needs to be set up so that it works?
Gradle version: 5.6.1
I think a good way to achieve what you want would be to use api
instead of implementation
. implementation
is meant to only keep the dependency inside the module, while api
is meant to export them along with the module. The dependencies for projA
would then become:
dependencies {
api("important-library:1.0")
}
This is the link to the official documentation: https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_separation