gorodkovskaya
gorodkovskaya

Reputation: 343

Use Kotlin Gradle plugin for tests only

I have a project and libraries with source code written in Java and tests written in Kotlin.

All projects are built by Gradle using Kotlin plugin.

But I noticed Kotlin is being added as transitive dependency to my libraries under the hood, even though I use Kotlin in tests only.

How could I avoid adding Kotlin as a transitive dependency?

settings.gradle:

pluginManagement {
    plugins {
        id 'org.jetbrains.kotlin.jvm' version '1.6.10'
    }
}

A common build.gradle:

plugins {
    id 'org.jetbrains.kotlin.jvm'
}

dependencies {
    testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
    testImplementation 'org.jetbrains.kotlin:kotlin-reflect'
    testImplementation 'org.jetbrains.kotlin:kotlin-test'
    testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5'
}

And when I build the dependency tree:

------------------------------------------------------------
Project ':commons-logging'
------------------------------------------------------------

testCompileClasspath - Compile classpath for compilation 'test' (target  (jvm)).
+--- org.mycompany:lib-logging:1.0.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0 -> 1.3.72
|         +--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72
|         |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.3.72
|         |    \--- org.jetbrains:annotations:13.0
|         \--- org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72
|              \--- org.jetbrains.kotlin:kotlin-stdlib:1.3.72 (*)
+--- org.mycompany:lib-core:3.0.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30 -> 1.3.72 (*)
+--- org.mycompany:lib-spring:3.0.0
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.30 -> 1.3.72 (*)

So all these Kotlin dependencies shall not be present in artifacts by org.mycompany

Upvotes: 1

Views: 42

Answers (0)

Related Questions