Multi-Project properties with Kotlin DSL


(Leigh Cooper) #1

Hi,

I’m looking for learning what the best practice is for storing dependency and plugin versions as Gradle properties in a multi-project build and having these properties available to all my subprojects.

I am using the Kotlin DSL for my build scripts.

For example I’d expect that I could define a property in my root project:

gradle.properties
graphQlJavaVersion=5.2.0

and be able to use this property anywhere throughout my multi-project build. I.e. in other build.gradle files. How ever I keep getting errors like:

Line 05: compile("com.graphql-java:graphql-java-servlet:$graphQlJavaVersion")
^ Unresolved reference: graphQlJavaVersion

How does every one else define versions once and use that version throughout the project? Could any one link me to some examples?


(Leigh Cooper) #2

So one solution (I hope there is a better solution) which works is:

gradle.properties
springBootVersion = 2.0.4.RELEASE

build.gradle (root project)

val springBootVersion: String by project`
extra {
   springBootVersion
}

subproject.build.gradle

dependencies {
   compile("org.springframework.boot:spring-boot-starter-data-jpa:${rootProject.extra.get("springBootVersion") as String}")
}

This comes from the Kotlin DSL example project https://github.com/gradle/kotlin-dsl/tree/master/samples/project-properties

Please note that spring-boot-starter-data-jpa has just been used as an example and is not part of the problem I’m trying to solve.