What are the different ways to handle version numb...
# gradle
b
What are the different ways to handle version numbers? For now I'm defining a variable twice, in my root of build.gradle.kts and in plugins
f
You could use
allprojects { version = "1234" }
if you want all your projects to have the same version.
b
I'm talking about buildSrc, plugins and the main
for my subprojects it works
Copy code
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

var ktorVersion = "1.3.2"
var serializationRuntimeVersion = "0.20.0"
var jenaVersion = "3.14.0"
var kotlinVersion = "1.3.71"
var arrowVersion = "0.10.4"
val rdf4kVersion = "0.1.1"
val springBootVersion = "2.2.5.RELEASE"
val moshiVersion = "1.8.0"
val jsonldVersion = "0.13.0"
val kotlinLoggingVersion = "1.7.6"
val woodstoxVersion = "5.2.0"
val junitApiVersion = "5.6.0"
val postgresVersion = "42.2.5"
val cliktVersion = "2.6.0"

plugins {
    val kotlinVersion = "1.3.71"
    id("nebula.kotlin") version kotlinVersion // sets up kotlin and kotlin versions
    kotlin("plugin.spring") version kotlinVersion
    kotlin("plugin.jpa") version kotlinVersion
    id("org.springframework.boot") version "2.2.5.RELEASE"
    id("io.spring.dependency-management") version "1.0.9.RELEASE"
    id("kotlinx-serialization") version kotlinVersion
    id("com.github.ben-manes.versions") version "0.21.0"
    //id("org.jetbrains.dokka") version "0.9.18"
}

buildscript {
    val kotlinVersion = "1.3.71"
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion")
        classpath(kotlin("gradle-plugin", kotlinVersion))
        classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
    }
}
so to update kotlin I have to change 3 lines…
f
It's not necessary that the Kotlin version of buildSrc matches with the version of the project. That said, the easiest way is to add a
buildSrc/settings.gradle.kts
file that configures the Kotlin plugin and you include that in your
settings.gradle.kts
file with
apply
.
Alternatively you could create a
.kotlin-version
file in the root and read its contents.
b
my question also extends to the versions of spring etc
so the only solution is to put it outside and read it
there were properties as well but I couldn't manage to read them both from plugins and the root
f
The Properties can only be read in the projects, so not inside plugins. It is possible to create more sophisticated systems to define and resolve versions but they all come with their drawbacks. An easy way is to define some
versions.gradle.kts
script with an
object v { const val foo = "1.2.3" }
in it which you then include. However, I believe that IntelliJ is still not able to auto-complete that for you.
b
oh turns out that with nebula I don't need that buildscript
f
You also don't need the
buildscript
as you have it with normal Gradle, unless you are using an ancient version.
b
you're right it works without