Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Nepomuk Seiler
    Regarding your other question. No it won't. It will use the name of the test package module.
    3 replies
    Jonas Amundsen
    Hi, I'm currently using sbt-native-packager to package my application into a single binary ( sbt stage), which I can add to docker images, etc. Is there a way for this binary to include the tests and run them through said binary? IE. to obtain kind of a self-diagnosing executable
    I'm using scalatest btw
    Gavin Bisesi
    Does sbt test:stage work? That's the first thing I'd try
    Jonas Amundsen
    It doens't seem like that creates anything different than sbt stage

    You can add a separate SBT project:

    val foo = project
    val fooTests = project
      .dependsOn(foo % "compile->test")

    this way Compile configuration in fooTests has all the test classes from foo.
    The hard thing would be to teach the scalatest runner to run and to detect all the tests. It should be doable (I've done something similar with Specs2 once), but it will probably turn out messy.

    Oh, and this probably doesn't have much to do with sbt-native-packager, since packaging has little bearing on this. As I've said, the hard part is wrangling your test framework.
    Martin Albarracin

    Hello, I have a problem with the settings

    mappings in Universal += (file("conf/custom.sh"), "bin/custom.sh")

    but in the console

    Reference to undefined setting: 
    [error]   Universal / mappings from Universal / mappings

    any ideas, thanks

    Phillip Schichtel
    Hi! I'm currently trying to build a small program using native-image using the GraalVMNativeImagePlugin with docker. The build fails however pretty early telling me it can't find Main$ in Main.main(String[]). As anyone here had a similar issue?
    Gavin Bisesi

    If I want to have several different docker images produced from the same multi-module codebase, what's the best way to do that?

    Ideally I also want to have minimal images that don't need much in the way of post-build bloat stripping

    Gavin Bisesi
    Also I'm running into this issue trying to set a version, "A setting cannot depend on a task"
    Gavin Bisesi
    ^ for multiple main classes, do I need to do something like setting up dummy sbt modules, and in each specific module, set a mainClass + docker image name, then docker:publishLocal for each of those?
    I'm used to using the java packaging where I just get multiple scripts
    Gavin Bisesi
    I wouldn't hate just having one docker image with multiple scripts that I need to pass arguments to in order to have it pick the specific launcher script

    huh, maybe my mappings aren't set up right?

    If I docker:stage I have target/docker/ with 1/ and 2/, but no library dependencies and 2/ just has the projectname-version.jar with nothing in it - is that taking from my root project?

    Do I need to scope the Docker / x settings to be projectWithMainClass / Docker / x?

    Gavin Bisesi
    ^ it was the scope; once I did that I was able to docker run --entrypoint /opt/docker/bin/main-class-one imgname:tag
    Gavin Bisesi
    is there a straightforward way I can generate multiple Dockerfiles with different names and different entrypoints?
    Gavin Bisesi
    hmm I think for my case (heroku) I can make a little launcher script myself, and then the deploys can all specify specifig CMD args to pass, which would pick the entry point... should do well enough I think
    Gavin Bisesi

    When I try to use docker:publish with dockerRepository as repository.heroku.com, I get this error:

    Get https://repository.heroku.com/v2/: x509: certificate is valid for *.herokuapp.com, herokuapp.com, not repository.heroku.com

    Anyone know why that might be?
    The heroku documentation uses that in their docs, it says to docker tag <image> repository.heroku.com/<appname>/<blah>; docker push repository.heroku.com/<appname>/<blah>, which as best I can tell is about what the plugin is generating

    It also seems like running docker:publish runs the normal publish and sends my jars too - how can I prevent that?
    [error] Get https://repository.heroku.com/v2/: x509: certificate is valid for *.herokuapp.com, herokuapp.com, not repository.heroku.com
    [error] java.lang.RuntimeException: Nonzero exit value: 1
    [error]     at scala.sys.package$.error(package.scala:30)
    [error]     at com.typesafe.sbt.packager.docker.DockerPlugin$.publishDocker(DockerPlugin.scala:688)
    [error]     at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings$53(DockerPlugin.scala:261)
    [error]     at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings$53$adapted(DockerPlugin.scala:260)
    [error]     at scala.collection.immutable.List.foreach(List.scala:392)
    [error]     at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings$52(DockerPlugin.scala:260)
    [error]     at com.typesafe.sbt.packager.docker.DockerPlugin$.$anonfun$projectSettings$52$adapted(DockerPlugin.scala:255)
    [error]     at scala.Function1.$anonfun$compose$1(Function1.scala:49)
    [error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
    [error]     at sbt.std.Transform$$anon$4.work(Transform.scala:67)
    [error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:281)
    [error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
    [error]     at sbt.Execute.work(Execute.scala:290)
    [error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:281)
    [error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
    [error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
    [error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    [error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    [error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    [error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    [error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    [error]     at java.lang.Thread.run(Thread.java:748)
    [error] (mymodule/ Docker / publish) Nonzero exit value: 1
    Gavin Bisesi

    If I turn on debug I see this:

    [debug] Executing docker push repository.heroku.com/myherokuapp/myimagename:6.2.1_14-09aeb5fc_20200917-1046

    (version from dynver)

    argh I had it set wrong
    it's registry.heroku.com not repository.
    Gavin Bisesi
    Gavin Bisesi
    also seems like publishLocal runs doc? I get warnings for doc output, which feels unfortunate since there's definitely no need for doc jars to be in the docker image
    Nepomuk Seiler
    @Daenyth publish running doc is a general sbt issue. You can disable building docs completely. I'm sure there are a few examples in this gitter chat ­čśé also playframework has some docs on this
    Gavin Bisesi
    I don't want to disable that in general; I publish jars using sbt-release-early (variation on it anyway)
    I just want want docker:publish to only publish docker and not other stuff too
    Gavin Bisesi
    can I provide some form of src/resources that's included just for docker builds but not added to published main jars?
    (example: I have a logback.xml I want to ship with my docker stuff, but I don't want to put a 'logback.xml' into the resources of jars that other libraries consume, since they have their own)
    (multi module project where some stuff is externally-consumed jars and other stuff is applications)
    Gavin Bisesi
    If I set Docker / publishTo := None, will docker:publish stop publishing my jars to my maven repo?
    I have a feeling that setting Docker / publish / skip := true will result in docker:publish not pushing images, correct?
    or would that work
    Gavin Bisesi
    what if I changed the task? Just make a new TaskKey and assign publishTask to it?
    and then I just don't invoke docker:publish
    Julien Blondeau
    Hello, is there any way to customize the systemd ExecStart value ?
    I would like to prefix the executable with an external script that fetches private passwords and inject them into the program environment variables
    Julien Blondeau
    I managed to override the whole systemd unit by creating the file src/templates/systemloader/systemd/start-template is it the right way ?
    Harshvardhan Chauhan
    Hi! docker output in sbt logs is showing up as error level is there a way to fix this?
    Harshvardhan Chauhan
    success] All package validations passed
    [error] #1 [internal] load .dockerignore
    [error] #1 transferring context: 2B done
    [error] #1 DONE 0.0s
    [error] #2 [internal] load build definition from Dockerfile
    [error] #2 transferring dockerfile: 1.49kB done
    [error] #2 DONE 0.0s
    [error] #3 [internal] load metadata for docker.io/library/openjdk:8
    [error] #3 DONE 2.8s
    [error] #4 [stage0 1/9] FROM docker.io/library/openjdk:8@sha256:ffb816515ac0fe5efff...
    [error] #4 DONE 0.0s
    [error] #8 [internal] load build context
    [error] #8 transferring context: 20.41kB done
    [error] #8 DONE 0.0s
    [error] #7 [stage0 2/9] WORKDIR /opt/docker
    [error] #7 CACHED
    [error] #9 [stage0 3/9] COPY opt /opt
    [error] #9 CACHED
    [error] #10 [stage0 4/9] COPY 1/opt /1/opt
    [error] #10 DONE 0.1s
    [error] #11 [stage0 5/9] COPY 2/opt /2/opt
    [error] #11 DONE 0.0s
    [error] #12 [stage0 6/9] RUN ["chmod", "-R", "u=rwX,g=rwX", "/opt/docker"]
    [error] #12 DONE 0.2s
    Sait Sami Kocata┼č

    hi everyone,

    not sure if it is correct place to post it but I am having an error like below when I try to use fat jar settings

    [info] resolving key references (25390 settings) ...
    [error] Reference to undefined setting:
    [error]   my-module / Universal / mappings from my-module / Universal / mappings (path\to\root\project\Deployment.scala:48)
    [error]         at sbt.internal.util.Init.Uninitialized(Settings.scala:369)
    [error]         at sbt.internal.util.Init.Uninitialized$(Settings.scala:356)
    [error]         at sbt.Def$.Uninitialized(Def.scala:21)
    [error]         at sbt.internal.util.Init.delegate(Settings.scala:263)
    [error]         at sbt.internal.util.Init.delegate$(Settings.scala:239)
    [error]         at sbt.Def$.delegate(Def.scala:21)
    [error]         at sbt.internal.util.Init.compiled(Settings.scala:195)
    [error]         at sbt.internal.util.Init.compiled$(Settings.scala:183)
    [error]         at sbt.Def$.compiled(Def.scala:21)
    [error]         at sbt.internal.util.Init.make(Settings.scala:205)
    [error]         at sbt.internal.util.Init.make$(Settings.scala:200)
    [error]         at sbt.Def$.make(Def.scala:21)
    [error]         at sbt.internal.Load$.$anonfun$apply$5(Load.scala:260)
    [error]         at sbt.internal.Load$.timed(Load.scala:1376)
    [error]         at sbt.internal.Load$.apply(Load.scala:255)
    [error]         at sbt.internal.Load$.defaultLoad(Load.scala:55)
    [error]         at sbt.BuiltinCommands$.liftedTree1$1(Main.scala:847)
    [error]         at sbt.BuiltinCommands$.doLoadProject(Main.scala:847)
    [error]         at sbt.BuiltinCommands$.$anonfun$loadProjectImpl$2(Main.scala:801)
    [error]         at sbt.Command$.$anonfun$applyEffect$4(Command.scala:149)
    [error]         at sbt.Command$.$anonfun$applyEffect$2(Command.scala:144)
    [error]         at sbt.Command$.process(Command.scala:187)
    [error]         at sbt.MainLoop$.process$1(MainLoop.scala:199)
    [error]         at sbt.MainLoop$.processCommand(MainLoop.scala:235)
    [error]         at sbt.MainLoop$.$anonfun$next$2(MainLoop.scala:147)
    [error]         at sbt.State$StateOpsImpl$.runCmd$1(State.scala:273)
    [error]         at sbt.State$StateOpsImpl$.process$extension(State.scala:277)
    [error]         at sbt.MainLoop$.$anonfun$next$1(MainLoop.scala:147)
    [error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:19)
    [error]         at sbt.MainLoop$.next(MainLoop.scala:147)
    [error]         at sbt.MainLoop$.run(MainLoop.scala:138)
    [error]         at sbt.MainLoop$.$anonfun$runWithNewLog$1(MainLoop.scala:116)
    [error]         at sbt.io.Using.apply(Using.scala:27)
    [error]         at sbt.MainLoop$.runWithNewLog(MainLoop.scala:110)
    [error]         at sbt.MainLoop$.runAndClearLast(MainLoop.scala:65)
    [error]         at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:50)
    [error]         at sbt.MainLoop$.runLogged(MainLoop.scala:41)
    [error]         at sbt.StandardMain$.runManaged(Main.scala:132)
    [error]         at sbt.xMain$.run(Main.scala:67)
    [error]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    [error]         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    [error]         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    [error]         at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    [error]         at sbt.internal.XMainConfiguration.run(XMainConfiguration.scala:45)
    [error]         at sbt.xMain.run(Main.scala:39)
    [error]         at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:111)
    [error]         at xsbt.boot.Launch$.withContextLoader(Launch.scala:130)
    [error]         at xsbt.boot.Launch$.run(Launch.scala:111)
    [error]         at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:37)
    [error]         at xsbt.boot.Launch$.launch(Launch.scala:119)
    [error]         at xsbt.boot.Launch$.apply(Launch.scala:20)
    [error]         at xsbt.boot.Boot$.runImpl(Boot.scala:56)
    [error]         at xsbt.boot.Boot$.main(Boot.scala:18)
    [error]         at xsbt.boot.Boot.main(Boot.scala)
    This is more or less what the settings look like, offending code is (mappings in Universal).value . I took this parts from the tutorial directly not sure what is wrong. I am using sbt 1.3.13
      lazy val settings = Seq(
        topLevelDirectory := None,
        javaOptions in Universal ++= Seq("-Dconfig.trace=loads")
      ) ++ dockerSettings ++ assemblySettings
      lazy val dockerSettings = Seq(???)
      lazy val assemblySettings = Seq(
        mappings in (Compile, packageDoc) := Seq(),
        test in assembly := {},
        assemblyJarName in assembly := name.value + ".jar",
        assemblyMergeStrategy in assembly := {
          case PathList("META-INF", xs @ _*) => MergeStrategy.discard
          case "application.conf"            => MergeStrategy.concat
          case x                             => MergeStrategy.first
      ) ++ fatJarSettings
      lazy val fatJarSettings = Seq(
        /*mappings in Universal := {
          val fatJar   = (assembly in Compile).value
          val filtered = (mappings in Universal).value.filter { case (file, name) => !name.endsWith(".jar") }
          filtered :+ (fatJar -> ("lib/" + fatJar.getName))
        scriptClasspath := Seq((assemblyJarName in assembly).value)
    @Deliganli, my guess is that for some reason UniversalPlugin isn't enabled. What plugins do you have enabled in your build.sbt (or in your project/*.scala files)?
    Sait Sami Kocata┼č
    putting enablePlugins(UniversalPlugin) explicitly in the module actually worked thank you @nigredo-tori . Looks like I got confused
    Leif Warner
    Is there a way to have the generated package make a /var/lib/myPackageName dir, for storing the service's persistence?
    Figure it could be the home dir of the user that it runs as.
    Hi, for a debian package, how can I change the user that is created on the target system? I create two deb files and I want them to use the same user on the target debian machine.
    Ah never mind, I guess I found it in the Java Server Application Manual