gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 432 forks source link

Runtime JAR files in the classpath should have the same version. These files were found in the classpath #1388

Closed winthrop-polk closed 5 years ago

winthrop-polk commented 5 years ago

I keep getting these errors. It seems to be related to transitive dependencies, how do people typically deal with this? It's really annoying, but I'm new to this. I've managed to make the list shorter, but also suspect it will get huge as I add more and more.


> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar
> Task :startScripts
> Task :distTar
> Task :distZip
> Task :assemble
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/usr/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.71/7512db3b3182753bd2e48ce8d345abbadc40fe6b/kotlin-reflect-1.2.71.jar (version 1.2)
    C:/Users/usr/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.71/d9717625bb3c731561251f8dd2c67a1011d6764c/kotlin-stdlib-1.2.71.jar (version 1.2)
    C:/Users/usr/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.3.41/2ecf4aa059427d7186312fd1736afedf7972e7f7/kotlin-stdlib-common-1.3.41.jar (version 1.3)
w: Consider providing an explicit dependency on kotlin-reflect 1.3 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath or use '-Xskip-runtime-version-check' to suppress this warning
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

group = "org.proj"
version = "1.0-SNAPSHOT"

buildscript {
    @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
    var kotlinVer: String by extra
    @Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
    var kotlinTestVer: String by extra

    @Suppress("UNUSED_VALUE")
    kotlinVer = "1.3.41"
    @Suppress("UNUSED_VALUE")
    kotlinTestVer = "2.0.7"
}

val kotlinVer: String by extra
val kotlinTestVer: String by extra

repositories {
    mavenCentral()
    jcenter()
}

plugins {
    kotlin("jvm") version "1.2.10"
    id("org.springframework.boot") version "2.1.6.RELEASE" apply false
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    application
    "java-platform"
}

dependencyManagement {
    imports {
        mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
    }
}

application {
    mainClassName = "org.proj.class"
}

dependencies {
    //Kotlin

    //implementation(kotlin(module = "stdlib-jdk7", version = kotlinVer))
    implementation("org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVer"){
        isTransitive = false
    }
    //implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVer")

    //Testing
    testImplementation("io.kotlintest:kotlintest:$kotlinTestVer")
    testImplementation("org.jetbrains.kotlin:kotlin-stdlib-common:$kotlinVer"){
        isTransitive = false
    }

    //Exposed SQL Framework
    implementation("mysql:mysql-connector-java:5.1.46")
    implementation("org.jetbrains.exposed:exposed:0.16.1"){
        isTransitive = false
    }
    //implementation(group = "org.slf4j", name = "slf4j-api", version = "1.7.25")
    //implementation(group = "org.slf4j", name = "slf4j-simple", version = "1.7.25")

    //Spring
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")

    implementation("joda-time:joda-time:2.10.3")
}

val compileKotlin by tasks.getting(KotlinCompile::class) {
    // Customise the "compileKotlin" task.
    kotlinOptions.jvmTarget = "1.8"
    doLast { println("-----Finished compiling Kotlin source code") }
}

val compileTestKotlin by tasks.getting(KotlinCompile::class) {
    // Customise the "compileTestKotlin" task.
    kotlinOptions.jvmTarget = "1.8"
    doLast { println("-----Finished compiling Kotlin source code for testing") }
}
eskatos commented 5 years ago

Your build script snippet mixes two kotlin versions (1.2.10 and 1.3.41) and your output snippet adds another one to the mix 1.2.71. Hard to know what is happening. A reproducer would help.

Please use the Gradle forums at https://discuss.gradle.org/ for support questions.