How to include test classes and test dependencies in sbt asssembly
Asked Answered
C

1

10

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)

Caul answered 7/1, 2015 at 16:52 Comment(0)
C
3

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

Caul answered 8/1, 2015 at 17:33 Comment(2)
I tried this way, however, I still cannot find the compiled test classes in the jar file. Do you mind posting your modified build.sbt? ThanksCalamus
you have to run test:assembly. There is no other modifiication to the fileCaul

© 2022 - 2024 — McMap. All rights reserved.