Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include test classes and test dependencies in sbt asssembly

I need to package my test classes, resources and also test dependencies with sbt assembly.

This question sbt-assembly : including test classes didn't help - test:assembly still didn't generate a jar with any of the desired classes included.

Note that my setup currently looks like this:

FooBuild.scala:

lazy val cucumberAssemblySettings = assemblySettings ++ Seq(
    mainClass in assembly := Some("cucumber.api.cli.Main"),
    jarName   in assembly := "cucumber.jar",
    mergeStrategy in assembly := {
      case "application.conf"     => MergeStrategy.concat
      case "logback.xml"          => MergeStrategy.last
      case x                      => defaultMergeStrategy(x)
    }
  )

And it's about the subproject foo-cucumber:

lazy val foo_cucumber = Project("foo-cucumber", file("foo-cucumber"))
    .settings(defaultSettings: _*)
    .settings(cucumberAssemblySettings: _*)
    .dependsOn(
      foo_test_server % "compile->compile;test->test",
      foo_test_utils % "compile->compile;test->test"
    )

even if I append (Test, assembly) in the settings above, I only get a jar (whose name is not the one specified, but the full name, with version) that does not contain test classes or dependencies, no matter whether I invoke sbt foo-cucumber/test:assembly or sbt foo-cucumber/assembly

How do I get a jar that has everything in it (compile and test classes and dependencies)

like image 867
Bozho Avatar asked Jan 07 '15 16:01

Bozho


1 Answers

The key for the multi-module project is to set the settings this way:

.settings(inConfig(Test)(cucumberAssemblySettings): _*)

and then not have any in (Test, assembly) in the settings

like image 170
Bozho Avatar answered Nov 08 '22 21:11

Bozho