Pihentagy
06/11/2024, 11:56 AMplugins {
id("org.springframework.boot") version "3.3.0"
id("io.spring.dependency-management") version "1.1.5"
kotlin("jvm") version "1.9.24"
kotlin("plugin.spring") version "1.9.24"
}
...
The kotlin("jvm") value is the kotlin version? Should it be equal to plugin.spring version? I do not know much about build.gradle(.kts), is there a basic article about the basics?
Can I upgrade and use kotlin 2.0?Robert Jaros
06/11/2024, 12:06 PMextra["kotlin.version"] = "2.0.0"Pihentagy
06/11/2024, 12:19 PMRobert Jaros
06/11/2024, 12:26 PMthanksforallthefish
06/11/2024, 1:02 PMgradle.properties
kotlin_version=2.0.0
# Spring Boot overrides
kotlin.version=${kotlin_version}
and in build.gradle (but should work similarly for kts file)
plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
//etc
}Klitos Kyriacou
06/11/2024, 1:06 PMkotlin(module: String) is just a convenience function that returns id("org.jetbrains.kotlin.$module"). That's good to know when you look at various example build.gradle.kts files and wonder why some use the kotlin function and others don't.Klitos Kyriacou
06/11/2024, 1:11 PMPihentagy
06/11/2024, 1:13 PM# Spring Boot overrides
Could you tell me about that override, @thanksforallthefish ?thanksforallthefish
06/11/2024, 1:18 PMgradle.propertie or in extra (as Robert was pointing out). I think there are also other ways to define those properties, but honestly 2 is already one-too-many for my tastePihentagy
06/11/2024, 1:25 PMgradle.properties in project root with content
kotlin_version=2.0.0
# Spring Boot overrides
kotlin.version=${kotlin_version}
and after that, in build.gradle.kts
kotlin("jvm") version "$kotlin_version"
kotlin("plugin.spring") version "$kotlin_version"
// allows all Kotlin classes in a project to be open for subclassing by default.
kotlin("plugin.allopen") version "$kotlin_version"
kotlin("plugin.jpa") version "$kotlin_version"
I get
* What went wrong:
Script compilation errors:
Line 12: kotlin("jvm") version "$kotlin_version"
^ Unresolved reference: kotlin_version
Line 13: kotlin("plugin.spring") version "$kotlin_version"
^ Unresolved reference: kotlin_version
Line 16: kotlin("plugin.allopen") version "$kotlin_version"
^ Unresolved reference: kotlin_version
Line 17: kotlin("plugin.jpa") version "$kotlin_version"
^ Unresolved reference: kotlin_versionKlitos Kyriacou
06/11/2024, 1:59 PMkotlin_version and kotlin.version are project properties, but the Kotlin DSL in your build file expects kotlin_version to be a Kotlin String variable. You can put this:
val kotlin_version: String by project
at the top of your build.gradle.kts file.Klitos Kyriacou
06/11/2024, 2:00 PMallopen plugin if you already have the spring plugin. Also, the plugins need to go in the plugins section, not the dependencies section where your kotlin("jvm") is.Pihentagy
06/11/2024, 2:09 PMkotlin_version=2.0.0
# Spring Boot overrides
kotlin.version=${kotlin_version}
extra["kotlin_version"]="2.0.0"
build.gradle.kts
import java.util.*
val kotlin_version: String by project
group = "xxxxxx"
version = Properties().apply { load(file("build.properties").inputStream()) }.getProperty("VERSION")
plugins {
id("org.springframework.boot") version "3.0.4"
id("io.spring.dependency-management") version "1.1.0"
id("jacoco")
id("org.sonarqube") version "3.3"
kotlin("jvm") version kotlin_version
kotlin("plugin.spring") version kotlin_version
kotlin("plugin.jpa") version kotlin_version
but still getting the same error.Pihentagy
06/11/2024, 2:12 PMKlitos Kyriacou
06/11/2024, 3:07 PMval kotlin_version inside your dependencies block (which is where you should define kotlin("jvm"), not in your plugins block). However, the plugins block unfortunately has restrictions which means you can't use this val inside the plugins block.thanksforallthefish
06/11/2024, 3:13 PMGString and kotlin string, but in groovy-gradle you can do
plugins {
id "org.jetbrains.kotlin.jvm" version "$kotlin_version"
}
however you cannot do
plugins {
id "org.jetbrains.kotlin.jvm" version kotlin_version
}
note: kotlin_version defined in gradle.properties. it's true the docs say Where «plugin id» and «plugin version» must be constant, literal strings. though
personally I haven't made the switch to kotlin-gradle yet, last time I tried it was too slow, though I think it was at least a couple of years ago and in the meantime a lot of improvements happenedthanksforallthefish
06/11/2024, 3:22 PMsettings file: https://github.com/gradle/gradle/issues/1697#issuecomment-655682357
//gradle.properties
kotlinVersion=2.0.0
kotlin.version=${kotlin_version}
// settings.gradle.kts:
pluginManagement {
val kotlinVersion: String by extra
plugins {
id("org.jetbrains.kotlin.jvm").version(kotlinVersion)
}
}
//build.gradle.kts
plugins {
// Apply plugins without versions:
id("org.jetbrains.kotlin.jvm")
}Klitos Kyriacou
06/11/2024, 3:25 PMPihentagy
06/11/2024, 3:25 PMthanksforallthefish
06/11/2024, 3:28 PM