|
Forking
sbt has movedsbt has now completely moved to GitHub. See https://github.com/harrah/xsbt/wiki/Forking. ForkingIntroductionBy default, the run action runs in the same JVM as sbt. Forking is required under certain circumstances, however. Or, you might want to fork Java processes when implementing new tasks. Forking runBasicsThe following examples demonstrate forking the run action and changing the working directory or arguments. override def fork = forkRun
override def fork =
forkRun(new File("different-working-directory"))
override def fork =
forkRun("-Xmx8G" :: Nil)
override def fork =
forkRun(
Some(new File("different-working-directory")),
"-Xmx8G" :: Nil
)AdvancedThe method to override in your project definition is fork, which is of type Option[ForkScala]. By default, it is None, which indicates forking is disabled. To enable forking, override fork to return an instance of ForkScalaRun (wrapped in Some). ForkScalaRun defines these methods: def runJVMOptions: Seq[String] = Nil def workingDirectory: Option[File] = None def javaHome: Option[File] = None def scalaJars: Iterable[File] = None By default, the forked process uses the same Java and Scala being used for the build and the working directory and JVM options of the current process. Override the above methods to use a different version. For example, to override the working directory used when running, do: def forkConfiguration = new ForkScalaRun { override def workingDirectory = Some(info.projectPath.asFile) }
override def fork = Some(forkConfiguration)Direct UsageTo fork a new Java process, use the Fork API. The methods of interest are Fork.java, Fork.javac, Fork.scala, and Fork.scalac. See the ForkJava and ForkScala classes for the arguments and types. The last argument in all cases is either the Logger to which output should go or the OutputStrategy to use (such as standard output or another OutputStream). | |
Is there a way to make a scala console session started from within sbt run in a forked jvm in the same way as this is possible for a program run?
no, sorry
If I override fork by defining a new ForkScalaRun without an implementation for scalaJars I get an error java.lang.RuntimeException: Scala jars not specified. The solution is to use the method forkRun(workingDirectory0: Option[File], jvmOptions: Seq[String]) which provides a good default for the scalaJars method.
Kbarros, please give an example.
My point was that forkRun provides a good default for the scalaJars method, whereas new ForkScalaRun{...} does not.
In other words, use the Basics section unless you know what you're doing.
forkRun is great but unfortunately it seems to put all output into the 'info' stream for logging. Without forkRun enabled output goes straight to the console. Is it possible to replicate this behaviour with forkRun enabled?