从sbt shell内设置环境变量 [英] Setting an environment variable from within the sbt shell

查看:212
本文介绍了从sbt shell内设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在交互式sbt shell中设置环境变量,但我似乎找不到解决方法。 (我查看了官方的sbt文档以及没有成功的stackoverflow)。

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).

我想明确表示我不想要,必须在 build.sbt 文件中设置此环境变量,但可以在交互式sbt shell会话中即时更改它,以便环境变量用于我运行的下一个sbt命令。

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.

例如,我希望能够(在sbt外壳内)执行以下操作:

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?

推荐答案

使用sbt 0.13.15 我发现唯一对我有用的是使用 eval

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

这篇关于从sbt shell内设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆