How to determine Kotlin version for old Gradle version? - kotlin

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?

Related

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

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.

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"

Kotlin Multiplatform project include cocoapod dependency

Trying to setup cocoapods for my Kotlin MPP:
plugins {
kotlin("multiplatform") version "1.5.10"
kotlin("native.cocoapods") version "1.5.10"
id("com.android.library")
id("maven-publish")
}
Syncing the project ends up in this error:
Execution failed for task ':podspec'.
> this and base files have different roots: C:\Users\user\AppData\Local\Temp\wrap6957loc\gradlew and G:\Workspace\tracking-lib.
I am on windows and always will be. The project should build on Windows and Mac. So I assume basic inclusion of that plugin should work?
What can I do to fix the paths?
This looks like a bug. The plugin should be disabled, but the build should be working fine. Please consider reporting it to https://kotl.in/issue The cocoapods plugin strongly relies on pre-installed components, such as Xcode CLI Tools, cocoapods and cocoapods-generate. All of them are described here. The iOS targets of the Kotlin MPP project themselves can't be built on Windows, this is a restriction of the compiler. See a full list of targets and their availability here.

Configure IntelliJ auto-completion for gradle script in kotlin

I am trying out gradle-script-kotlin with simple hello-world application in IntelliJ. But IntelliJ auto-completion doesn't popup in build.gradle.kts file.
https://github.com/gradle/gradle-script-kotlin/tree/master/samples/hello-world
build.gradle.kts:
apply<ApplicationPlugin>()
configure<ApplicationPluginConvention> {
mainClassName = ".HelloWorld"
}
configure<JavaPluginConvention> {
setSourceCompatibility(1.8)
setTargetCompatibility(1.8)
}
repositories {
jcenter()
}
dependencies {
testCompile("junit:junit:4.12")
}
settings.gradle:
rootProject.buildFileName = 'build.gradle.kts'
I have IntelliJ kotlin plugin and gradle plugin installed and using gradle 3.0. The sample application works with gradle commands.
How to configure IntelliJ to enable auto-completion on build.gradle.kts file?
I'm using IntelliJ 2016.2.2 with kotlin plugin version: 1.0.3-release-IJ2016.1-120
Had the same problem. Gradle script Kotlin requires version 1.1x of the IntelliJ Kotlin plugin.
Follow these steps to install it:
https://github.com/gradle/gradle-script-kotlin/tree/master/samples#install-idea-kotlin-plugin
The regular update channel only updates to version 1.0.3x right now.
Update 18/06:
The github readme has been updated to include:
(Note: this version will not work with the official Gradle 3.0 release, stick to the official EAP 1.1 from JetBrains if you intend to use Gradle 3.0)
If you manually installed version 1.1.0-dev-2222 earlier, uninstall it and restart IntelliJ.
Install version 1.1.x from the EAP Channel
This version works with Kotlin-Script in Gradle 3.0.
In IntelliJ, press:
Tools => Kotlin => Configure Kotlin Updates.
Select
Early Access Preview 1.1
and press
Check for updates now.
Download the latest plugin.
If it gives an error, just restart IntelliJ, it will have installed the plugin.
I tried gradle 3.1 with kotlin-plugin-1.1.0-dev-2222.zip in intellij 2.5. And it works for me.
Here is my intellij version:
IntelliJ IDEA 2016.2.5
Build #IC-162.2228.15, built on October 14, 2016
JRE: 1.8.0_112-release-287-b2 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
And the steps:
1, Download the kotlin-plugin-1.1.0-dev-2222.zip in https://github.com/gradle/gradle-script-kotlin/tree/master/samples and install the plugin in Idea
2, Create a gradle java project in Idea, and choose to use gradle wrapper
3, In the terminal, under the project directory, use "./gradlew wrapper --gradle-version=3.1" to switch to gradle 3.1
4, Create a file "build.gradle.kts" under the root directory of the project
5, Add rootProject.buildFileName = 'build.gradle.kts' in the settings.gradle file
6, Add codes in build.gradle.kts, and if the auto-completion does not work, try "Refresh all projects" in the Gradle Tool Window.
7, If it still not work, restart your Idea
Here is a github repo: https://github.com/kolyjjj/gradle-kotlin-test
Try re-importing the project by selecting settings.gradle.