https://kotlinlang.org logo
Title
m

Marcel Overdijk

12/14/2017, 5:31 PM
In Groovy
build.gradle
I typically define (reusable) ext properties in my build scripts like:
buildscript {
    ext {
        javaVersion                     = "1.8"
        kotlinVersion                   = "1.2.0"
        springBootVesion                = "2.0.0.M7"
        querydslVersion                 = "4.1.4"
        querydslGradlePluginVersion     = "1.0.8"
    }
And the I can refer to these properties when declaring plugins and dependencies. What is the proper way to this within Kotlin DSL?
b

bamboo

12/14/2017, 5:34 PM
While it’s possible to define
ext
properties in Kotlin, a better approach for constants might be having something like the following in `buildSrc/src/main/kotlin/Libs.kt`:
kotlin
object Libs {
   val javaVersion = “1.8”
   ...
}
👍 1
that way you get code completion when editing build scripts
Libs.<...>
m

Marcel Overdijk

12/14/2017, 6:05 PM
thx for the suggestion, I ended up using `val`s but I will look into your approach as well
b

bamboo

12/14/2017, 6:06 PM
if they are all being used in a single place, keeping them as local vals is better
c

Czar

12/15/2017, 7:50 AM
@bamboo my root project is groovy based, but I want to have object Libs exactly like you proposed here. When I add buildSrc/src/main/kotlin/Libs.kt it is not recognised and during gradle build I see following which tells me that kotlin in buildSrc is not expected and not compiled
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy NO-SOURCE
:buildSrc:processResources NO-SOURCE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test NO-SOURCE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE
e

eskatos

12/15/2017, 9:13 AM
@Czar you should apply the
kotlin-dsl
plugin in
buildSrc/build.gradle.kts
to get the Kotlin compiler setup properly
c

Czar

12/15/2017, 11:33 AM
Thank you!