简体   繁体   中英

Setting an environment variable from within the sbt shell

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM