In Groovy `build.gradle` I typically define (reusa...
# gradle
m
In Groovy
build.gradle
I typically define (reusable) ext properties in my build scripts like:
Copy code
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
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`:
Copy code
kotlin
object Libs {
   val javaVersion = “1.8”
   ...
}
👍 1
that way you get code completion when editing build scripts
Libs.<...>
m
thx for the suggestion, I ended up using `val`s but I will look into your approach as well
b
if they are all being used in a single place, keeping them as local vals is better
c
@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
Copy code
: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
@Czar you should apply the
kotlin-dsl
plugin in
buildSrc/build.gradle.kts
to get the Kotlin compiler setup properly
c
Thank you!