Search code examples
sbtsbt-native-packager

How to add a project-test.jar to a package?


For our test servers, we want to package our tests in a debian. In sbt, I can generate the test-jar using:

publishArtifact in Test := true

I've looked into using member in Universal and addArtifact() but I am having trouble finding a solution.

How do I add the test-jar into the package?


Solution

  • There are two options.

    Add to mappings

    This is very simply done with this small snippet you can add to your build.sbt

    mappings in Universal += {
      // generates the test package
      val testjar = (packageBin in Test).value
      // maps this file to your lib folder in your output package
      testjar -> s"lib/${testjar.getName}"
    }
    

    Add it to publishTask

    This will generate the test package and publishes it, too. But it won't be added to the debian package.

    import com.typesafe.sbt.packager.SettingsHelper
    SettingsHelper.addPackage(Debian, packageBin in Test, "jar")