There are several questions here on Stackoverflow regarding the Kotlin compiler warning when different versions of Kotlin jars are mixed in the classpath.
This question is a different one and concerns the situation when you are developing Gradle plugins using Kotlin. When you have at least one of the following:
kotlin-dslplugin is applied;java-gradle-pluginplugin is applied;gradleApi()dependency is added;gradleKotlinDsl()dependency is added;
And you have Kotlin plugin like kotlin("jvm") version "1.4.10", e.g.:
plugins {
java
kotlin("jvm") version "1.4.10"
`kotlin-dsl`
`java-gradle-plugin`
}
You will get famous:
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
bla-bla-bla/gradle-6.7/lib/kotlin-stdlib-1.3.72.jar (version 1.3)
bla-bla-bla/modules-2/files-2.1/.../kotlin-stdlib-jdk8-1.4.10.jar (version 1.4)
and so on for every Kotlin jar
w: Consider providing an explicit dependency on kotlin-reflect 1.4 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
Here Kotlin 1.3.72 is the embedded version for Gradle 6.7, and Kotlin 1.4.10 is the one you added manually.
The problem is with gradleApi() or gradleKotlinDsl() because they add Kotlin jars directly as local filesystem files, thus bypassing Gradle dependency versions resolution.