英文:
Running Gradle task with environment variables
问题
我有以下的Gradle任务:
任务 runCli(type: JavaExec) {
group = "执行"
description = "运行CLI工具"
classpath = sourceSets.main.runtimeClasspath
main = "commandline.CommandLineToolKt"
}
然后,在项目根目录下,我运行:
export MONGODB_HOST=localhost && ./gradlew runCli
在我的代码中,我有:
System.getenv("MONGODB_HOST")
当我运行这个应用程序时,我得到:
Exception in thread "main" java.lang.IllegalStateException: System.getenv("MONGODB_HOST") 不能为 null
英文:
I have the following Gradle task:
task runCli(type: JavaExec) {
group = "Execution"
description = "Run the CLI tool"
classpath = sourceSets.main.runtimeClasspath
main = "commandline.CommandLineToolKt"
}
Then, in the project root folder, I run:
export MONGODB_HOST=localhost && ./gradlew runCli
In my code, I have:
System.getenv("MONGODB_HOST")
When I run the app, I get:
Exception in thread "main" java.lang.IllegalStateException: System.getenv("MONGODB_HOST") must not be null
专注分享java语言的经验与见解,让所有开发者获益!
评论