我正在使用最新版本的SBT(似乎很难弄清楚版本是什么).我想将系统属性传递给我的应用程序,sbt run如下所示:
sbt -Dmyprop=x run
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
ScalaTest 套件正在使用
System.getProperty("my.command-line.property")
Run Code Online (Sandbox Code Playgroud)
sbt命令行是什么来实现这个设置呢?
我努力了
SBT_OPTS="-Dmy.command-line.property=foo" sbt "test-only <path to test suite"
Run Code Online (Sandbox Code Playgroud)
还:
JAVA_OPTS="-J-Dmy.command-line.property=foo" sbt "test-only <path to test suite"
Run Code Online (Sandbox Code Playgroud)
最后:
sbt/sbt '; set javaOptions in Test +="-Dtest.num.points=500000"; \
project mllib; test-only org.apache.spark.mllib.optimization.LBFGSSuite'
Run Code Online (Sandbox Code Playgroud)
当使用任何这些尝试时,System.getProperty 都会显示为空白。
一种有效的方法是从 Intellij 中运行 ScalaTest 并在运行配置中将JVM 参数设置为-Dmy.command-line.property=foo 。
我正在编写一个需要特定设置的插件: configUrl
如果我指定我的设置build.conf将如下所示:
MyPlugin.configUrl := "http://..../..."
Run Code Online (Sandbox Code Playgroud)
然后我可以使用命令行来执行此操作:
sbt 'set MyPlugin.configUrl := "http://..../..."' performAction
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法可以让我在构建中没有这个设置?
如果我sbt没有设置启动,我会收到以下错误:
[error] Reference to undefined setting:
[error]
[error] *:config-url from *:application-configuration
Run Code Online (Sandbox Code Playgroud)
我搜索谷歌但无法找到在命令行上提供设置的方法,如下所示:
sbt config-url="http://..../..."
Run Code Online (Sandbox Code Playgroud) 借用这个有用的答案,我试图传递-Dfoo=bar给sbt console.
鉴于SBT项目只有build.sbt:
$cat build.sbt
scalaVersion := "2.11.8"
fork := true
Run Code Online (Sandbox Code Playgroud)
我试过:
$sbt '; set javaOptions += "-Dfoo=bar" ; console'
scala> sys.props.get("foo")
res0: Option[String] = None
Run Code Online (Sandbox Code Playgroud)
但是,我曾预料到Some("bar")而不是None给出这个set ...论点.
但是,使用sbt ... run按预期工作:
$cat src/main/scala/net/Main.scala
package net
object Main {
def main(args: Array[String]): Unit =
println("sys.props.get('foo'): " + sys.props.get("foo"))
}
$sbt '; set javaOptions += "-Dfoo=bar" ; run'
[info] Running net.Main
[info] sys.props.get('foo'): Some(bar)
Run Code Online (Sandbox Code Playgroud)
我如何foo=bar …