Automatically getting dependencies of other modules


I have a multi-project build (

The one module depends on some abstracted testing code that I have inside another module called “:shared:testutils”. This module has JUnit as one of its dependencies as its some abstracted test functionality using JUnit.

Now - I want to use it another module. And it works.
In the other module:

apply plugin: "java"

version = "1.0.0"

dependencies {
    compile project(":shared:testutils")

    testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.2"
    testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.2"

My question -
Can I automatically import the dependencies from the “:shared:testutils” module. In other words, can I somehow remove the explicit referencing of JUnit in the code segment above?

This is just an example. I have a few :shared:* modules and I constantly have to repeat their dependencies when I use them?

Thank you kindly for any help.
I scanned through the documentation on composite builds and cross project publications ( but thought I’d just ask for some direction on a conceptual level. I tried a few things but with no success :frowning:

Thank you :slight_smile:

Conceptually, :shared:testutils is a library. You should apply the java-library plugin instead of just java and declare the JUnit dependencies as api dependencies. However, it’s odd that your the project shown has a compile dependency on it. It seems more likely this should be a testImplementation dependency unless this project’s actual purpose is also to be a module used in other module tests.