使用环境变量运行Gradle任务

huangapple 未分类评论48阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年5月5日 22:08:38
  • 转载请务必保留本文链接:https://java.coder-hub.com/61615094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定