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?
Is there any way to set an environment variable from a Gradle build (in the build.gradle file)? I've tested it in isolation: the values do get passed and my test task receives everything, be it a systemProperty, environment variables or jvmArgs. So, it's nothing wrong with Gradle itself here.
Gradle properties such as org.gradle.caching=true that are typically stored in a gradle.properties file in a project root directory or GRADLE_USER_HOME environment variable. Environment variables such as GRADLE_OPTS sourced by the environment that executes Gradle.
System properties Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle.properties files with the prefix systemProp.
Gradle provides multiple mechanisms for configuring behavior of Gradle itself and specific projects. The following is a reference for using these mechanisms. When configuring Gradle behavior you can use these methods, listed in order of highest to lowest precedence (first one wins): Command-line flags such as --build-cache.
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")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With