adamsmith
adamsmith

Reputation: 5999

How to share common test dependency version in Gradle?

I'm following this Gradle User Guid with kotlin DSL, trying to make sub projects to use the dependency version specified in root project. Here is part of the root build.gradle.kts:

plugins {
    `java-platform`
}

dependencies {
    constraints {
        api("com.google.guava:guava:28.0-jre")
        api("org.testng:testng:6.14.3")
    }
}

Here is the build.gradle.kts of a sub project:

plugins {
    `java-library`
}

dependencies {
    testImplementation("org.testng:testng")
}

val test by tasks.getting(Test::class) {
    useTestNG()
}

When I run ./gradlew run in the project root directory, it goes fine. However, when I run ./gradlew test it complains:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':misc:java:compileTestJava'.
> Could not resolve all files for configuration ':misc:java:testCompileClasspath'.
   > Could not find org.testng:testng:.
     Required by:
         project :misc:java

I've searched all over the web but with no luck. I guess I should use something like testapi("org.testng:testng:6.14.3") in root build script.

Upvotes: 0

Views: 1320

Answers (1)

Louis Jacomet
Louis Jacomet

Reputation: 14500

As answered in the comments already, you are missing a reference to the platform in your subproject:

dependencies {
    implementation(platform(rootProject)) // Will use the constraints defined in the platform

    testImplementation("org.testng:testng")
}

Upvotes: 1

Related Questions