Search code examples
scalasbtdpkgsbt-native-packager

simplify settings for deb only build with sbt native packager


I am trying to package my scala main app code as a .deb file. the app will only run on an ubuntu machine, so I do not really care about windows etc.

Currently, I am struggling to find the most easiest way to compile the .deb using the simpliest settings. Let's assume I have a simple object Kernel extends App scala file in my src folder that should be bundled inlcuding the jardependencies.

my current scala based debian settings for the project are:

import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys.


  val debSettings = mapGenericFilesToLinux ++ linuxSettings ++ debianSettings ++ Seq( 
    name in Debian := "my-app",
    version in Debian := "0.1-version",
    mainClass := Some("Kernel"),
    packageSummary := "",
    target := new java.io.File("target"),
    packageDescription := "my app",
    packageDescription := "my app desciption",
    NativePackagerKeys.normalizedName := "normalizedName",
    maintainer := "my name",
    sourceDirectory := new java.io.File("./src"),
    debianPackageDependencies in Debian ++= Seq("openjdk-7-jre"),
    debianPackageRecommends in Debian ++= Seq(),
    linuxPackageMappings in Debian ++= Seq() ,
    debianMaintainerScripts ++=Seq())

the debian:package-bincall works and a deb is created but no binaries/jars are copied into the deb so i'm obviously missing some configuration. i know that there are still missing linuxPackageMappings etc but i'm wondering if there is an easier configuration for the compilation? using packageArchetype.java_server forces me to include so many not-used variables for windows etc. I want to avoid this.

Any suggestion how to simplify the settings + mappings for a deb-only build?


Solution

  • You can just pull in the settings that are relevant to you from:

    https://github.com/sbt/sbt-native-packager/blob/master/src/main/scala/com/typesafe/sbt/packager/archetypes/JavaServerApplication.scala#L24

    and

    So, this should be something like:

    import com.typesafe.sbt.packager.archetypes._
    
    packagerSettings
    
    mapGenericMappingsToLinux
    
    JavaAppPackaging.settings
    
    JavaServerAppPackaging.debianSettings
    

    caveat the correct imports. Let's cover what each of these do:

    1. packagerSettings adds the basic "flow" of the packager tasks, but does not configure any of the files or settings
    2. mapGenericMappingsToLinux is the hook which will take everything configured in mappings in Universal and attempt to make it linux friendly for linux packages.
    3. JavaAppPackaging.settings will take your build definition, and automatically fill out the mappings in Universal configuration with defaults for your application.
    4. JavaServerAppPackaging.debianSettings adds additional settings specifically for debian such that the bundled default application can be started as a server.

    One of the goals of the plugin is to allow you the flexibility to use any of these "mappings" and get default behavior or override. It's just not well documented how. I hope this helps!