How to set the version of the Kotlin compiler in a non-Android project? - kotlin

I am running into a compile error when trying to compile a project with Kotlin and Compose Multiplatform, I think due to the Compose 1.1.0 compiler extension not being compatible with Kotlin 1.6.21. Even though I set my Kotlin plugin version to 1.6.10:
plugins {
idea
kotlin("jvm") version "1.6.10"
id("org.jetbrains.compose") version "1.1.0"
}
I get this error:
Kotlin: kotlinc-jvm 1.6.21-release-334 (JRE 15+36-1562)
Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin androidx.compose.compiler.plugins.kotlin.ComposeComponentRegistrar is not compatible with this version of compiler
I can't figure out how to set the version of the Kotlin compiler that is used. From the log above the error, I can see it's using version 1.6.21-release-334, rather than some 1.6.10 version.
An alternate possible solution would be to change the version of the Compose Kotlin Compliler plugin to a more recent alpha or beta version that supports Kotlin 1.6.21, but I can't figure out how to do that either. In an Android project, you would use:
android {
composeOptions {
kotlinCompilerExtensionVersion = "1.2.0-beta03"
}
}
However, I would rather solve this by setting the Kotlin compiler so I won't run into the issue again whenever the latest version of Kotlin outpaces the compatibility of the Compose Multiplatform Kotlin Compiler Plugin.

The main idea I was thinking about is that there are some other places in the existing project where the old version 1.6.21 was used or some other setups that require that version or maybe an old cache. So basically need to clean the project, even delete the .idea directory of the project, and check other places where the old version can be set. After that reopen the project, do cleanup, sync and rebuild it.

Related

How to determine Kotlin version for old Gradle version?

I have an existing project using Gradle 5.6.3, which is currently building Java-only Android. I'd like to add a library in Kotlin.
I had IntelliJ generate a library module, which gave me the following configuration:
plugins {
id 'org.jetbrains.kotlin.android'
}
and in my parent project
buildscript {
dependencies {
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30'
}
}
However, when I run this, it fails, saying The current Gradle version 5.6.3 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin.
Because of reasons, upgrading Gradle is not an option for the project right now. So I want to satisfy Gradle by using "the previous version".
I already looked at the compatibility matrix, but that only says that Gradle is tested with Kotlin 1.3.72 through 1.6.0., which isn't helpful.
So, which version of the kotlin-gradle-plugin do I need if I want to stay on Gradle 5.6.3?

How to get a recent Kotlin version in a multi-project Gradle setup with Kotlin DSL

Setup
I setup a Gradle multi-project project, including the Kotlin DSL as described on in the Gradle documentation. My Gradle version is 7.4.1, which is the recent version at the time of writing.
In this part of the documentation we are told to use convention plugins for subproject configuration and we should not use subprojects or allprojects DSL.
That is the reason I ended up having
plugins {
`kotlin-dsl`
}
in my buildSrc/build.gradle.kts, which is all working as expected.
Problem
By using kotlin-dsl I'm wired to gradle-kotlin-dsl-7.4.1.jar (Gradle version, I mentioned earlier). This jar seems to specify all Kotlin related versions along the project; i.e. I cannot do this to specify my Kotlin version
plugins {
`kotlin-dsl`
kotlin("jvm") version "1.6.10"
// ...
}
Because two different Kotlin versions will appear
$ ./gradlew build
> Configure project :buildSrc
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.5.31` that might work differently than in the requested version `1.6.10`.
That behaviour and the warning are described here.
Questions
Am I able to use a more recent version of Kotlin in this setup, if so: how?
Out of curiosity: where do I see the Kotlin version tracked, that is baked into Gradle? I could not find any notice in the last hand full of release notes
atm there is no way to update the embedded version of the Kotlin the kotlin-dsl plugin relies on (github.com/gradle/gradle/issues/16345)
I think your best bet would be the gradle github
(github.com/gradle/gradle/issues/19308)

InteliJ desktop compose project compile issue

I am making a desktop app using Kotlin compose(IntelliJ version 2021.2.1). My project is still running but I am getting these compile errors in the kotlin compose code.
"Check your module classpath for missing or conflicting dependencies"
Here are my project configurations
As a solution, I removed cashe in .gradle and restart IDE with invalidating cashe but didn't work. and changed JDK versions and kotlin versions as well but still getting the same output.
Your project uses pretty outdated versions of both kotlin and Compose.
Check out that your Compose Multiplatform IDE Support plugin is up to date, the latest version for today is 1.0.0-alpha4-build331
Latest versions of plugins for build.gradle.kts:
kotlin("jvm") version "1.5.21"
id("org.jetbrains.compose") version "1.0.0-alpha3"

What is the recommended IntelliJ setup for Kotlin Multiplatform

I've been trying to get an environment for working with Kotlin (multiplatform) for a little too long now and would like some advice. I seem to get stuck on which version of JDK do I need, should I download Android Studio for the Android SDK or is there a cleaner way than getting the full IDE, which version of IntelliJ to use and which version of the Kotlin plugin is compatible.
I would like to use Kotlin 1.3.
My aim is to develop a common library with no platform-specific code; though I would like to test it on Android, Linux, WebAssembly.
Lubuntu 18.04.1
Intel x64
I'd suggest using the Kotlin Multiplatform Plugin which just came out. Its setup is very simple:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.2.71'
}
repositories {
mavenCentral()
}
kotlin {
targets {
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js')
fromPreset(presets.mingwX64, 'mingw')
}
sourceSets { /* ... */ }
}
It comes with built-in presets for all supported platforms but you can also set them up individually. I've worked with the "old way" of doing multiplatform development and using this plugin will just make it infinitely easier to deal with. You can read more about setting it up here.
You should target Java 6 code if you're planning to use the library in Android and not having any headaches. Note that you need to specify that explicitly to the Kotlin compiler. Only setting the IntelliJ IDEA project to target Java 6 won't do.
The JDK version doesn't really matter since you can tell the compiler to generate code for any previous Java version.
IntelliJ IDEA is probably the best IDE for Kotlin since it's made by JetBrains, the same guys that are behind Kotlin itself. Get the latest version.
You don't need any extra plugin, Kotlin is supported out of the box by IntelliJ IDEA (i.e. Kotlin plugin is included in the standard version).

The binary version of its metadata is 1.0.1, expected version is 1.1.0

In intellij idea 16 EAP 144.3357.4 I have a pure Kotlin cmd project currently refusing to run with this error:
The binary version of its metadata is 1.0.1, expected version is 1.1.0
The project runs on the command-line - I invalidated caches and restarted Idea - nothing helped. Anyone had the same problem and found a way to get it working?
The problem seems to be mismatch between the kotlin library used in your project and the version of the plugin are not compatible.
Check the Kotlin plugin version and you'll most likely see something similar to:
Version: 1.0.0-rc-1007-IJ143-11
Then check the version of the Kotlin libraries by looking into META-INF/build.txt or META-INF/MANIFEST.MF and it'll most likely be other version like 1.0.0-beta-4589.
To resolve the problem update Kotlin libraries to version 1.0.0-rc-1007 which can be found in this maven repository: https://dl.bintray.com/kotlin/kotlin-eap.
Kotlin compiler marks each .class with #kotlin.Metadata to indicate, among others:
The version of the bytecode interface (naming conventions, signatures) of the class file annotated with this annotation.
That is how the compiler detected incompatibilities.