SBT run single test class in submodule - scala

I have a multi module project with moduleA, moduleB, and moduleC. I want to run my class com.helpme.run.MyTest from moduleB.
My guess is the sbt command should look like:
sbt "project moduleA" --mainClass com.helpme.run.MyTest test
But no luck. Please help!! Thanks!

First of all you can run a test by using testOnly
$ sbt testOnly MyTest
But if your project is a multi-project sbt project and you have the same test class with the same name in more than one project you can navigate between projects by project command and then run the test
$ sbt
> project moduleA
> testOnly MyTest
Note that you have to first run sbt and then run the rest of commands from the sbt shell.

Depends on your project configuration testOnly couldn't work
You can try this command too:
sbt "project myProject" "testOnly com.this.is.my.Test"

Related

compile/package multiple configurations from command line sbt scala

is there a way to build/compile all configurations at once? I have a project that has a Dev configuration in addition to the default Compile and Test configuration, and i am looking for a command or a setting in my build.sbt that would allow me to compile/package all 3 configurations at once.
Basically looking for a way to avoid having to do these 3 commands to build the entire source tree:
sbt compile
sbt dev:compile
sbt test:compile
When I use sbt from IntelliJ it is able to do this on building the project, but I am looking to do this from the command line.
First, you can run multiple tasks with a single sbt invocation:
sbt compile dev:compile test:compile
Second, you could define an alias in your build which does what you want:
addCommandAlias("compileAll", "; compile; dev:compile; test:compile")
Then, just run sbt compileAll.

Build subproject in Spark with sbt

I want to build subproject in Spark with sbt. I found this example and it works
$ ./build/sbt -Phive -Phive-thriftserver (build)
sbt (spark)> project hive (switch to subproject)
sbt (hive)> testOnly *.HiveQuerySuite -- -t foo ( run test case)
However, I tried the following but it does not build but quit
./build/sbt -mllib
I do not know how does the author figure out -Phive -Phive-thriftserver. I cannot find this in Spark source code.
I just want to do the exact same thing as the example but with a different subproject.
This is not asking how to use projects to print out all available projects.
Specify the project scope:
./build/sbt mllib/compile
refer to: http://www.scala-sbt.org/0.13/docs/Scopes.html

Run scalatest in main instead of test through sbt?

Say I have a Scalatest file in the main directory, is there a sbt command to run the test such as testOnly or `runMain'? On IntelliJ, you are given the option to run the test.
You should be able to use test-only. From the scalatest user guide:
test-only org.acme.RedSuite org.acme.BlueSuite

sbt-assembly: Create jar for a single project of a multi-project build

I have a multi-project build.sbt file. I would like to assemble the jar for just one of the projects. Currently, I do the following:
$ sbt
project analysis
assembly
...
exit
I would like to save a few steps and assemble the jar for the project "analysis" from the command line. Is there a way to do this?
Thanks.
You can use sbt without its REPL:
$ sbt analysis/assembly

Using the RootProject feature of sbt to do something other than 'sbt compile'

I'm trying to use the RootProject feature of SBT to download another project from a git repo, for example:
lazy val schwatcher = RootProject(uri("https://github.com/lloydmeta/schwatcher.git"))
lazy val root = project in file(".") dependsOn schwatcher
This successfully downloads the git repo and basically runs the "sbt compile" command on the git repo, compiling all of the classes. However, I'd like it to go one step beyond running the usual "sbt compile" command. Instead, I want it to run "sbt package" so that a jar file is produced. Is there any way to do this?
Thanks.
Have you tried using the One-Jar SBT plugin? I used it a while back for another project and it was simple to use.
There is also the sbt-assembly plugin, which is more maintained.