Sbt options for java in a dynamic task

I am trying to write a task that takes an input argument, pass it to the testOnly task and execute. It works fine, but I can’t establish the correctness of the system in this task, which will be visible in the test. These properties should not affect other tasks and should be visible only in this custom task.

Here is my sample code

lazy val myTestOnly = InputKey[Unit]("myTestOnly", "test only with special sys prop") val myTestOnlyTask = myTestOnly := { Def.inputTaskDyn { val args: Seq[String] = spaceDelimited("").parsed javaOptions in Test ++= Seq("-Dfoo=bar") // does not work testOptions += Tests.Setup(() => System.setProperty("foo", "bar")) //does not work System.setProperty("foo", "bar") // does not work (testOnly in Test).toTask(" " + args.head) }.evaluated } 

When I start the sbt console

  myTestOnly com.sampleTest 

testOnly is running, but the "foo" property is not displayed

So qustion - how to set a property in the task definition that will be displayed in the test version only for the current task?

+6
source share
1 answer

in the build.sbt file:

 val currentTimestamp: String = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) val targetDir : String = baseDirectory + "/project/target/mtd/" + currentTimestamp javaOptions in Test ++= Seq("-Ddynamic_dir_to_set=" + targetDir) 

and sbt test will have a guaranteed value for dynamic_dir_to_set env var.

A couple of theoretical links for the passage:

http://www.scala-sbt.org/0.13.2/docs/Detailed-Topics/Forking.html#change-working-directory http://www.scala-sbt.org/0.13/docs/Plugins-and -Best-Practices.html

0
source

Source: https://habr.com/ru/post/970470/


All Articles