Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build.gradle.kts & multi-module-project: how to add other project so that transitive dependencies are available too

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

like image 744
Roland Avatar asked Dec 31 '25 23:12

Roland


1 Answers

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

like image 54
gscaparrotti Avatar answered Jan 03 '26 14:01

gscaparrotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!