Hi ! I will try to repost my question :confused: `...
# android
g
Hi ! I will try to repost my question 😕
Copy code
What could happen if I would use different libraries with different kotlin version ?

Do you update your project's kotlin language's version only when all the imported libraries are updated ?
🚫 3
g
Thanks ! I will read all the documentation 🙂 I asked because gradle tell to me:
Copy code
Runtime JAR files in the classpath should have the same version. These
files were found in the classpath:
and
Copy code
w: Consider providing an explicit dependency on kotlin-reflect 1.5 to
prevent strange errorsw: Some runtime JAR files in the classpath have
an incompatible version. Consider removing them from the classpath
e
use kotlin-bom to keep versions aligned, that can happen if you have dependencies on older kotlin-reflect that you yourself aren't directly depending on
👍 1
g
I don't already read the links, but what happen if a library that I'm import, uses an old version of kotlin (such as 1.3) and I have set the 1.5 in the project ? In this case I suppose gradle gives me an error, but in which way the project can build and run ? What happen ff the library uses a method that doesnt exist anymore in 1.5 ? Maybe the answer is in the documentation that you sent to me, sorry ! (Maybe I misunderstanding the gradle's error)
e
if you're using Kotlin/JVM, it works fine. the standard library is backwards-compatible and does not remove stable APIs from the ABI. (sometimes they may be removed from the API, but in a way that preserves ABI compatibliity)
the problem is that all of the standard library should be aligned - that includes kotlin-stdlib (which your build pulls in automatically) and kotlin-reflect (which it doesn't). if you used
Copy code
dependencies {
    implementation(platform(kotlin("bom"))) // Kotlin Gradle DSL
    implementation platform("org.jetbrains.kotlin:kotlin-bom:$kotlin_version") // Groovy Gradle DSL (probably, I don't use it)
}
then Gradle will make sure all the standard library artifact versions are aligned, regardless of which ones are included transitively
there is no forwards compatibility - you can't use a library compiled with a newer major release of Kotlin without issues - but there is a promise of backwards compatibility, at least for Kotlin/JVM. (does not apply to multiplatform)
please read the documentation to understand what is in scope and what isn't.
g
Thanks ! You are the best ! I will read ! I am ashamed of my ignorance..
c
@ephemient I didn't know that kotlin had a bom! Cool thanks
e
bom discoverability is definitely an issue in the maven ecosystem… something that could be better in gmm https://blog.gradle.org/alignment-with-gradle-module-metadata
🤗 1
g
Hi @ephemient , good morning ! I read the two link: In the first one I understand that: "Many of these components were officially released as Stable which means that they are evolved in the backward-compatible way following the principles of Comfortable Updates and Keeping the Language Modern" In the second link: "The Kotlin Language Committee has to approve every incompatible change before it lands in a stable version." But I'm wondering, how an "incompatible change" can be backward-compatible ?
e
there are source-level incompatible changes that are binary-level compatible
👍 1
g
Thanks 🙂 I add this code line into app's gradle:
Copy code
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
but when I execute the clean task the warning appears:
Copy code
Task :buildSrc:compileKotlin
w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
    C:/Users/""/.gradle/wrapper/dists/gradle-6.7.1-all/2moa8rlfac5eqlcfgk98k0deb/gradle-6.7.1/lib/kotlin-stdlib-1.3.72.ja
r (version 1.3)
    C:/Users/""/.gradle/wrapper/dists/gradle-6.7.1-all/2moa8rlfac5eqlcfgk98k0deb/gradle-6.7.1/lib/kotlin-stdlib-common-1.
3.72.jar (version 1.3)
    C:/Users/""/.gradle/wrapper/dists/gradle-6.7.1-all/2moa8rlfac5eqlcfgk98k0deb/gradle-6.7.1/lib/kotlin-stdlib-jdk7-1.3.
72.jar (version 1.3)
    C:/Users/""/.gradle/wrapper/dists/gradle-6.7.1-all/2moa8rlfac5eqlcfgk98k0deb/gradle-6.7.1/lib/kotlin-stdlib-jdk8-1.3.
72.jar (version 1.3)
    C:/Users/""/.gradle/wrapper/dists/gradle-6.7.1-all/2moa8rlfac5eqlcfgk98k0deb/gradle-6.7.1/lib/kotlin-reflect-1.3.72.j
ar (version 1.3)
    C:/Users/""/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.5.0/65fbc439df2e4aad1f376976
2d54534f1b564090/kotlin-stdlib-jdk8-1.5.0.jar (version 1.5)
    C:/Users/""/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.5.0/f61904618ea7be07a66e0545
ffe8dc2c70a19b77/kotlin-stdlib-jdk7-1.5.0.jar (version 1.5)
    C:/Users/""/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.4.31/63db9d66c3d20f7b8f66196e7ba
86969daae8b8a/kotlin-reflect-1.4.31.jar (version 1.4)
    C:/Users/""/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.5.0/29dae2501ca094416d15af0e21470
cb634780444/kotlin-stdlib-1.5.0.jar (version 1.5)
    C:/Users/""/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.5.0/4080d69efca5e39e9b4972
f125e40f1607bd6460/kotlin-stdlib-common-1.5.0.jar (version 1.5)
w: Consider providing an explicit dependency on kotlin-reflect 1.5 to prevent strange errors
w: Some runtime JAR files in the classpath have an incompatible version. Consider removing them from the classpath
I'm not understanding anything.. 😥
e
wait, are you doing this inside Gradle buildSrc or plugin?
because you cannot use newer Kotlin version there, due to Gradle issues. inside build.gradle.kts or any buildscript in a project using Gradle Kotlin DSL, you can only use the same version of Kotlin that is bundled in Gradle
g
The error is only in buildSrccompileKotlin, there aren't error during the compilation of other's app module. I have imported the
Copy code
implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
in the app's gradle. In the buildSrc I have devoloped a task to get the jacoco-plugin coverage, and I'm importing the last gradle version:
Copy code
apply plugin: 'java-gradle-plugin'
apply plugin: 'kotlin' 

buildscript {
    ext.gradle_version = '4.2.1'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
        classpath "com.android.tools.build:gradle:$gradle_version"
    }
}

repositories {
    google()
    jcenter()
}

dependencies {
    // Android gradle plugin will allow us to access Android specific features
    implementation "com.android.tools.build:gradle:$gradle_version"
    implementation "com.android.tools.build:gradle-api:$gradle_version"
}

gradlePlugin {
    plugins {
        create("AndroidCoveragePlugin") {
            id = "AndroidCoveragePlugin"
            implementationClass = "com.myApp.buildtools.AndroidCoveragePlugin"
        }
    }
}
Inside agp 4.2.1 there aren't kotlin 1.5.0 ?
e
no
😂 1
Lint does bundle yet another Kotlin version, but it's in a different classloader
g
Gradle is tested with Kotlin 1.3.21 through 1.4.0.
..... Which it means I can't resolve the issue, if I would keep the project to the last kotlin version. In this case I have to live with the warning, and I have to hope that the gradle plugin continue to working well.
e
no, that's not what it means.
at least upgrade to Gradle 6.8.or 6.9 - they embed Kotlin 1.4, although still using 1.3 syntax in build.gradle.kts for compatibility reasons
Gradle 7 build scripts can use Kotlin 1.4 in full
g
I have upgraded to gradle 6.8 and I have set the plugin to the kotlin version 1.4.32 and I have add the kotlin-reflect 1.4.32. Now it works without warning ! Thanks @ephemient!