Setting an environment variable from within the sbt shell

假装没事ソ 提交于 2020-07-30 05:22:21

问题


I would like to be able to set an environment variable from within the interactive sbt shell, and I can't seem to find a way to do that. (I have looked on the official sbt docs as well as on stackoverflow without success).

I want to make it clear that I don't want to have to set this environment variable in the build.sbt file, but rather be able to change it on the fly on my interactive sbt shell session, so that the environment variable is used for the next sbt commands I run.

For example, I would like to be able to do something like (from within the sbt shell):

> set_environment_variable("foo", "foo_value")
> `mymodule`/run
> (... program runs and completes)
> set_environment_variable("foo", "another_foo_value")
> `mymodule`/run

Is this possible? And if it is, how can I do it?


回答1:


Using sbt 0.13.15 the only thing I've found which has worked for me is to use eval.

> eval System.setProperty("foo", "foo_value")
> `mymodule`/run
> ...
> eval System.setProperty("foo", "another_foo_value")
> `mymodule`/run


来源:https://stackoverflow.com/questions/48327218/setting-an-environment-variable-from-within-the-sbt-shell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!