Build Gradle dependency from source

In my multiplatform project I added a dependency on org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.2. I am using version 1.4-M1, and when I try to compile I get the following error:

w: Skipping "/home/elias/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-collections-immutable-linuxx64/0.3.2/37bf3b196f204496096d1ec13af209a788c5ddae/kotlinx-collections-immutable.klib" as it is a pre 1.4 library
e: Could not find "/home/elias/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlinx/kotlinx-collections-immutable-linuxx64/0.3.2/37bf3b196f204496096d1ec13af209a788c5ddae/kotlinx-collections-immutable.klib" in [/home/elias/prog/array_kotlin/array, /home/elias/.konan/klib, /home/elias/.konan/kotlin-native-linux-1.4-M1/klib/common, /home/elias/.konan/kotlin-native-linux-1.4-M1/klib/platform/linux_x64].

This is because the gradle artifact does not contain compiled binaries for 1.4-M1. This is understadable. What is the easiest way to get this to work? I can always download the source code and build it myself, but I’d rather not add such complication to the build process.

Is there a way in which I can tell Gradle to download the source and build it instead of expecting binaries of the correct version? Even if I wait for a version of this library that is built with the correct version of Kotlin, the same problem will happen again next time I upgrade Kotlin and th edeveloper of this library doesn’t deploy a new version in time.

What version of gradle re you using? If between 5.4.x and 6.x have you enabled metadata?
Also what Kotlin plugin are you using, multiplatform or JVM/JS/Native?

The library may have been pushed without Gradle metadata or you may not have them enabled.

I’m using 5.5.1, and with regards to metadata, I don’t know. I don’t think so. I added the following to the main gradle file, and that did not change the behaviour (i.e. I’m still getting errors the binaries are incompatible with 1.4-M1):


This is the config file in question:

I have now upgraded Gradle to 6.3, and there is no difference in behaviour.

I’m starting to think that there is no way to have the build actually compile the dependency from source. Is this the case?

You are probably using Kotlin 1.4-M1 while the library is built for 1.3.71.
The Kotlin/JVM binaries are retrocompatible while the Kotlin/Navite are not (not sure about JS).

Set your Kotlin version to 1.3.72 (or 1.3.71) and you should be fine.

Yes, I understood that. The problem that I’m concerned about it not speficially about 1.4-M1 but any upgrade. If the binaries are not compatible, then this problem will happen every time a new version is released. It implies that if any of the libraries I depend on are late in rebuilding their binaries, I will be stuck and not being able to upgrade Kotlin.

If this is the case, it would seem as though one has to be very careful when linking third-party libraries to make sure they are well maintained and always keeps up to date with the latest Kotlin releases.

The ability to automatically build from source would solve this problem, and if that isn’t actually supported it would seem a better way to handle this would be to simply include the library as a git submodule instead.

K/N is in beta. Incompatibilities between version is expected. You have to wait until K/N stabilizes before expecting stable features.

If you need to quickly build from sources, you can use Gradle to do so. Have a look at this blog post.