Search code examples
kotlinbuild.gradlegradle-kotlin-dsl

Setting environment variables in build.gradle.kts


In groovy you can set environment variables with environment key value. For example for run you can do:

run {
    environment DB_HOST "https://nowhere"
}

How can I accomplish this in Kotlin in build.gradle.kts?


Solution

  • Like this:

    tasks {
        "run"(JavaExec::class) {
            environment("DB_HOST","https://nowhere")
        }
    }
    

    Or if you like the delegation property style:

    val run by tasks.getting(JavaExec::class) {
        environment("DB_HOST","https://nowhere")
    }