2016-05-13 3 views
1

Занимаясь от этого полезного answer, я попытался пройти -Dfoo=bar до sbt console.Пропустить Системное свойство `sbt console`?

Учитывая проект SBT, имеющий только в build.sbt:

$cat build.sbt 
scalaVersion := "2.11.8" 

fork := true 

Я попытался:

$sbt '; set javaOptions += "-Dfoo=bar" ; console' 

scala> sys.props.get("foo") 
res0: Option[String] = None 

, но я ожидал 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) 

Как я могу передать foo=bar как системное свойство к console?

ответ

1

я могу получить свойства системы с помощью консоли со следующими:

sbt console -Dturkey=fried 

scala> sys.props.get("turkey") 
res1: Option[String] = Some(fried) 
5

run вилок, но console не так просто sbt -Dfoo=bar console

В случае необходимости вы можете установить его:

  • in sbt shell с eval sys.props("foo") = "bar"
  • в REPL (console) с sys.props("foo") = "bar"
  • в build.sbt с val setFoo = sys.props("foo") = "bar"
Смежные вопросы