Starting a Gui application from within SBT (OSX) - swt

I am trying to start a jface/swt application (I know oldschool but legacy demand),from within SBT. jface/swt application requires the option "-XstartOnFirstThread"
I have tried to add
javaOptions := Seq("-XstartOnFirstThread", "-d64"),
fork in run := true
But it does not work. Any idea how i can do that? or even if it possible?

Setting javaOptions in run should help, as documented in the reference manual.
build.sbt
javaOptions in run := Seq("-XstartOnFirstThread", "-d64")
fork in run := true

Related

SBT: add command-line parsing to modify settings for existing tasks

When running tasks (e.g., test, jmh:run), I often want to specify javaOptions which are tedious to type by hand (e.g., to dump program data).
This is my current approach:
// build.sbt
lazy val myProject = project
...
.settings(
...
Test / javaOptions ++= if (sys.props.get("dump").nonEmpty) Seq("-X...", ...) else Nil
)
I can set system properties on sbt launch (e.g., sbt -Ddump) and then check them with sys.props, but changing these properties requires me to reload sbt. I would like to parse some arguments when the task is invoked, such that I can write test -dump and modify the Test / javaOptions setting accordingly.
Is this possible? Someone recommended I override the default task but I'm having trouble figuring out what that would look like. I have a suspicion I need an InputTask for this, but also don't know what that'd look like.
You don’t need to reload sbt, if you are running sbt in a shell, you will need to programtically call‚ sys.props.set

sbt per-user settings in multi-project build

How should I store per-user settings in sbt 1.0+ with a multi-project build? The way recommended in https://www.scala-sbt.org/0.12.3/docs/Detailed-Topics/Best-Practices.html#local-settings doesn't work with a child project build.sbt like
val sshUser = settingKey[String]("SSH user")
val sshUser := "user"
and child project local.sbt like
sshUser := "synapse"
with the error error: not found: value sshUser
First of all, when using SBT 1.0+ I'd recommend to read the documentation corresponding to that version: SBT 1.0 Best Practices. Your link leads to very old documentation for a long deprecated sbt version.
Still, the local.sbt is a valid one even in sbt 1.0. However, if you want to apply your setting to several or all projects in a multi project build, you need to tell SBT so:
ThisBuild / sshUser := "synapse"
See here. Otherwise, the setting is only applied to the root project.

Disabling parallel execution for scct:test in SBT?

I've been working on a Scala application. To do it properly, I want the kernel of my code to be completely covered by tests. To do that, I'm using the SCCT plugin for SBT.
Unfortunately, my tests rely on an in-memory database (h2). Therefore, my tests cannot run in parallel. However, sbt runs all tasks in parallel by default.
To solve this, I've modified build.sbt file to disable parallel execution of the tests as:
parallelExecution in Test := false
The problem with the build configuration is that to generate code coverage, I need to run sbt scct:test rather than sbt test.
I've tried to disable the parallel execution of scct:test but the code below does not compile:
parallelExecution in scct:test := false
Can anyone help me by either disabling the parallel execution in scct:test by either setting the flag, or by making scct:test run in the test context?
I think the task name is actually ScctTest. Try:
parallelExecution in Test := false
parallelExecution in ScctTest := false
Have you considered creating a new database for each test and making the db name that is created be a random name for each one so they dont clash. Works well as long as you dont have absolutely massive numbers of tests which require a database.

sbt test-only not picking up jvm option when forking a jvm for tests

I have the following lines in my build.sbt
fork := true
javaOptions in run += "-Dmy.environment=local"
javaOptions in test += "-Dmy.environment=local"
This works totally fine when I use the "test" command in sbt and when my code checks the jvm system settings for my.environment, it finds the correct value (i.e., "local").
The problem that I am having is that when I run "test-only org.whatever.SomeTest" in this case the my.environment key isn't in the jvm system settings. Specifically, System.getProperty("my.environment") is null whereas it was "local" when I just ran "test".
Does anyone know how to fix this?
You are likely hitting #975: regression: fork in test doesn't work anymore, which is currently under review. Try:
javaOptions in Test += "-Dmy.environment=local"

How to turn off parallel execution of tests for multi-project builds?

I have a multi-project build with tests in sub-projects and in a parent project. The build is aggregated so that the parent project runs all tests in child projects.
I configured it so that there's no parallel execution of tests in both the sub-projects and the parent project, via
parallelExecution in Test := false
However, I have the nagging feeling that tests that span over multiple projects are ran in parallel. In the case of one of the sub-projects this is a problem because it mutates state in a test database concurrently, leading to the test to fail.
Any ideas as to how to globally switch of parallel execution of tests, between projects?
I think you can apply a setting across projects using scope ThisBuild, like
parallelExecution in ThisBuild := false
I don't know if you can combine that with scope Test, but it might not be necessary.
To restrict the number of concurrently executing tests in all projects, use:
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1)
See sbt documentation
See discussion
This worked for me in 1.1.0:
Test / parallelExecution := false
See my answer here How to run subprojects tests (including setup methods) sequentially when testing
There is another way to prevent parallel execution. You can make the test tasks of the different projects depend on each other:
test in Project2 := (test in Project2).dependsOn(test in Project1).value
parallelExecution in Test in Project2 := false
Another possibility, based on https://stackoverflow.com/a/27068019/1922026, is to define a command alias in the root project:
.settings(addCommandAlias("test", ";s1/test;s2/test;s3/test"): _*)
where s1, s2 and s3 are the sub-projects. When you are in root project and run "test" the tests will be executed sequentially and in the order defined.
You can try also Global / parallelExecution := false
The "modern" (i.e. sbt 1.x) equivalent of disabling parallel execution in Test scope is to add the following to your build.sbt:
Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)
For those not familiar with sbt syntax, in context you want to do something like:
lazy val main = project
.in(file("."))
.settings(
name := "foo",
// more settings
// ...
Global / concurrentRestrictions += Tags.limit(Tags.Test, 1)
)
From the tags and rules section of sbt docs.
p.s. quite a useful setting for ScalaTest, particularly around setup/teardown logic during database testing. Fixes some quite puzzling non-deterministic errors that you'll ineviitably hit with parallel execution enabled.