diesieben07
03/16/2021, 7:44 PMkotlin {
sourceSets.all {
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn")
}
}
I would like to move this into buildSrc so in the modules I can just do:
kotlin {
configureExperimentalAnnotations()
}
To do this, I'd want to do this as an extension function on KotlinProjectExtension
, but I have no idea which dependency I need in the buildSrc
Gradle script for that. kotlin-gradle-plugin
doesn't have it.
Any advice?tapchicoma
03/16/2021, 7:57 PMKotlinPluginExtension
should be available when you will add kotlin-gradle-plugin
as a buildSrc
module dependency.tapchicoma
03/16/2021, 7:58 PMdiesieben07
03/16/2021, 8:10 PMdependencies {
implementation(kotlin("gradle-plugin"))
}
in the build.gradle.kts in buildSrc. I do have the jar as a dependency now, but the package that contains KotlinPluginExtension
is empty in the jar filetapchicoma
03/16/2021, 8:11 PM1.4.31
?diesieben07
03/16/2021, 8:11 PMdiesieben07
03/16/2021, 8:12 PMplugins {
kotlin("jvm") version "1.4.31"
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("gradle-plugin"))
}
diesieben07
03/16/2021, 8:13 PMimport org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
This import doesn't work in the buildSrc code (it works in the build.gradle.kts file)tapchicoma
03/16/2021, 8:16 PMplugins {
`kotlin-dsl`
}
tapchicoma
03/16/2021, 8:19 PMimplementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31")
notationdiesieben07
03/16/2021, 8:19 PMkotlin("jvm")
plugin on the main build.gradle.kts must not include a version. But if I remove that version, I am not specifying a version anywhere, which one will it use?diesieben07
03/16/2021, 8:21 PMdiesieben07
03/16/2021, 8:23 PMtapchicoma
03/16/2021, 8:25 PMimplementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.4.31")
and you need to add gradlePluginPortal()
to the repositories { }
Also I've checked plugin jar file and KotlinJvmProjectExtension
class file is there 🤔diesieben07
03/16/2021, 8:30 PMtapchicoma
03/16/2021, 8:41 PMKotlinProjectExtension
in your sample project:tapchicoma
03/16/2021, 8:41 PMdiesieben07
03/16/2021, 8:42 PMdiesieben07
03/16/2021, 8:45 PMrm -rf ~/.gradle
diesieben07
03/16/2021, 8:52 PMdiesieben07
03/16/2021, 8:52 PMdiesieben07
05/18/2021, 7:00 PMWith it then listing the Kotin stdlib that is shipped with Gradle (1.3.72) and my version (1.4.31, now 1.5.0). Now with Kotlin 1.5.0 this breaks completely:Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16.I have reinstated my test-repository here: https://github.com/diesieben07/kotlin-dsl-buildsrc-bug Any advice?
diesieben07
05/18/2021, 7:20 PMtapchicoma
05/18/2021, 7:21 PMtapchicoma
05/18/2021, 7:22 PMdiesieben07
05/18/2021, 7:27 PMtapchicoma
05/18/2021, 7:27 PMdiesieben07
05/18/2021, 7:28 PMdiesieben07
05/18/2021, 7:28 PMudalov
(no idea why Kotlin 1.4 accepts the 1.5 jars, but 1.3 doesn’t?)Thanks for bringing this up, it is indeed unclear and we should document this. Since Kotlin 1.3, Kotlin/JVM metadata has “up to 1 version” forward-compatibility policy. So 1.3 can read metadata of classes compiled with Kotlin from 1.0 to 1.4.255; 1.4 can read metadata from 1.0 to 1.5.255, and so on.
diesieben07
05/18/2021, 8:43 PMdiesieben07
05/27/2021, 8:17 PMdiesieben07
05/27/2021, 8:28 PMdiesieben07
05/27/2021, 8:31 PM