{"id":13665243,"url":"https://github.com/xerial/sbt-pack","last_synced_at":"2025-05-15T12:02:30.902Z","repository":{"id":5551778,"uuid":"6756045","full_name":"xerial/sbt-pack","owner":"xerial","description":"A sbt plugin for creating distributable Scala packages.","archived":false,"fork":false,"pushed_at":"2025-04-17T00:20:14.000Z","size":2021,"stargazers_count":496,"open_issues_count":35,"forks_count":77,"subscribers_count":13,"default_branch":"main","last_synced_at":"2025-05-14T12:10:00.931Z","etag":null,"topics":["docker","makefile","sbt-plugin","scala"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xerial.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2012-11-19T06:44:58.000Z","updated_at":"2025-05-12T15:15:55.000Z","dependencies_parsed_at":"2023-10-11T16:08:20.252Z","dependency_job_id":"9099e524-ec69-4da6-aa9c-baa5d6768779","html_url":"https://github.com/xerial/sbt-pack","commit_stats":{"total_commits":797,"total_committers":40,"mean_commits":19.925,"dds":0.4153074027603513,"last_synced_commit":"ddb7861ee8805a6c21de165647a2b1a73b739d34"},"previous_names":[],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xerial%2Fsbt-pack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xerial%2Fsbt-pack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xerial%2Fsbt-pack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xerial%2Fsbt-pack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xerial","download_url":"https://codeload.github.com/xerial/sbt-pack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337612,"owners_count":22054253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","makefile","sbt-plugin","scala"],"created_at":"2024-08-02T06:00:30.608Z","updated_at":"2025-05-15T12:02:30.723Z","avatar_url":"https://github.com/xerial.png","language":"Scala","readme":"sbt-pack plugin [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.xerial.sbt/sbt-pack/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.xerial.sbt/sbt-pack)\n========\n\nA sbt plugin for creating distributable Scala packages that include dependent jars and launch scripts.\n\n### Features\n\n- `sbt pack` creates a distributable package in `target/pack` folder.\n  - All dependent jars including scala-library.jar are collected in `target/pack/lib` folder. This process is much faster than creating a single-jar as in `sbt-assembly` or `proguard` plugins. \n  - Supporting multi-module projects.\n  - Useful for creating runnable [Docker](https://www.docker.com) images of Scala programs\n- `sbt packArchive` generates `tar.gz` archive that is ready to distribute.\n  - The archive name is `target/{project name}-{version}.tar.gz`\n- `sbt pack` generates program launch scripts `target/pack/bin/{program name}`\n  - To run the program no need exists to install Scala, since it is included in the lib folder. Only java command needs to be found in the system.\n  - It also generates `.bat` launch scripts for Windows users. \n- Generates a Makefile for program installation.\n  - Do `cd target/pack; make install`. Then you can run your program with `~/local/bin/{program name}`\n- You can install multiple versions of your program in the system.\n  - The above Makefile script uses a separate folder for each version (e.g., `~/local/{project name}/{project version}`). \n  - The latest version is linked from `~/local/{project name}/current`\n- You can add other resources in `src/pack` folder. \n  - All resources in this folder will be copied to `target/pack`.\n- Check duplicated classes in dependencies.  \n\n* [Release Notes](ReleaseNotes.md)\n\n### Usage\n\nAdd `sbt-pack` plugin to your sbt configuration:\n\n**project/plugins.sbt**\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.xerial.sbt/sbt-pack/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.xerial.sbt/sbt-pack)\n\n```scala\n// for sbt-0.13.x, sbt-1.x\naddSbtPlugin(\"org.xerial.sbt\" % \"sbt-pack\" % \"(version)\")  \n```\n\nRepository URL: https://repo1.maven.org/maven2/org/xerial/sbt/\n\n#### Minimum configuration\n\n**build.sbt**\n```\n// [Required] Enable plugin and automatically find def main(args:Array[String]) methods from the classpath\nenablePlugins(PackPlugin)\n\n// [Optional] Specify main classes manually\n// This example creates `hello` command (target/pack/bin/hello) that calls org.mydomain.Hello#main(Array[String]) \npackMain := Map(\"hello\" -\u003e \"org.mydomain.Hello\")\n```\n\nNow you can use `sbt pack` command in your project.\n\n#### Full build configuration\n\nsbt-pack will generate launcher scripts for calling `def main(args:Array[String]): Unit` method. You can manually set the `packMain` variable to specify mappings from launcher scripts to their corresponding main classes (for example `packMain := Map(\"hello\" -\u003e \"myprog.Hello\")`) will create `target/pack/bin/hello` script and it will call `myprog.Hello` method. \n\nIf `packMain` setting is missing, sbt-pack will find main classes in your code and generates launcher scripts for them. The main classes must be Scala objects that define `def main(args:Array[])` method. The program names will be the main classes names, hyphenized. (For example, main class `myprog.ExampleProg` gives program name `example-prog`.) \n\n\n**build.sbt**\n\n```scala\n// [Required] Enable plugin and automatically find def main(args:Array[String]) methods from the classpath\nenablePlugins(PackPlugin)\n\nname := \"myprog\"\nbase := file(\".\")\n    \n// [Optional] Specify mappings from program name -\u003e Main class (full package path). If no value is set, it will find main classes automatically\npackMain := Map(\"hello\" -\u003e \"myprog.Hello\")\n\n// [Optional] JVM options of scripts (program name -\u003e Seq(JVM option, ...))\npackJvmOpts := Map(\"hello\" -\u003e Seq(\"-Xmx512m\"))\n\n// [Optional] Extra class paths to look when launching a program. You can use ${PROG_HOME} to specify the base directory\npackExtraClasspath := Map(\"hello\" -\u003e Seq(\"${PROG_HOME}/etc\")) \n\n// [Optional] (Generate .bat files for Windows. The default is true)\npackGenerateWindowsBatFile := true\n\n// [Optional] jar file name format in pack/lib folder\n//   \"default\"   (project name)-(version).jar \n//   \"full\"      (organization name).(project name)-(version).jar\n//   \"no-version\" (organization name).(project name).jar\n//   \"original\"  (Preserve original jar file names)\npackJarNameConvention := \"default\",\n\n// [Optional] Patterns of jar file names to exclude in pack\npackExcludeJars := Seq(\"scala-.*\\\\.jar\")\n\n// [Optional] Generate a text file containing the list of copied jars.\npackJarListFile := Some(\"lib/jars.mf\")\n\n// [Optional] List full class paths in the launch scripts (default is false) (since 0.5.1)\npackExpandedClasspath := false\n// [Optional] Resource directory mapping to be copied within target/pack. Default is Map(\"{projectRoot}/src/pack\" -\u003e \"\") \npackResourceDir += (baseDirectory.value / \"web\" -\u003e \"web-content\")\n\n// [Optional] Environment variables\npackEnvVars := Map(\"hello\" -\u003e Map(\"key1\" -\u003e \"value1\", \"key2\" -\u003e \"value2\"))\n\n// To publish tar.gz, zip archives to the repository, add the following lines:\nimport xerial.sbt.pack.PackPlugin._\npublishPackArchives\n\n// Publish only tar.gz archive. To publish another type of archive, use publishPackArchive(xxx) instead\n//publishPackArchiveTgz\n\n// [Optional] Set a root folder name of archive contents. (defualt is (project-name)-(version). Setting this to an empty string is useful for packaging projects for AWS lambda. \npackArchiveStem := \"\"\n```\n\n**src/main/scala/Hello.scala**\n\n```scala\npackage myprog\n    \nobject Hello {\n  def main(args:Array[String]) = {\n    println(\"Hello World!!\")\n  }\n}\n```\n\n#### Command Examples\n\n**Create a package**\n\n    $ sbt pack\n\nYour program package will be generated in `target/pack` folder.\n\n**Launch a command**\n\n    $ target/pack/bin/hello\n    Hello World!!\n\n**Install the command**\n\nInstall the command to `$(HOME)/local/bin`:\n```\n$ sbt packInstall\n```\n\nor\n\n```\n$ cd target/pack; make install\n```\n\nTo launch the command:\n```    \n    $ ~/local/bin/hello\n    Hello World!\n```\n\nAdd the following configuration to your .bash_profile, .zsh_profile, etc. for the usability:\n```\nexport PATH=$(HOME)/local/bin:$PATH\n```\n\n**Install the command to the system**\n\n   \n    $ cd target/pack\n    $ sudo make install PREFIX=\"/usr/local\"\n    $ /usr/local/bin/hello\n    Hello World!\n\n\n**Create a tar.gz archive of your Scala program package**\n\n    $ sbt packArchive\n\n### Copy dependencies\n\nThe `packCopyDependencies` task copies all the dependencies to the folder specified through \nthe `packCopyDependenciesTarget` setting.\n\nBy default, a symbolic link will be created.  By setting `packCopyDependenciesUseSymbolicLinks` to `false`, \nthe files will be copied instead of symlinking.   A symbolic link is faster and uses less disk space.\n\nIt can be used e.g. for copying dependencies of a webapp to `WEB-INF/lib`\n\nSee an [example](src/sbt-test/sbt-pack/copy-dependencies) project.\n\n### Example projects\n\nSee also [examples](src/sbt-test/sbt-pack) folder\nin the source code. It contains several Scala project examples using sbt-pack.\n\n### Use case\n\n- scala-min: A minimal Scala project using sbt-pack: \u003chttps://github.com/xerial/scala-min\u003e\n - A minimal project to start writing Scala programs. \n\n\n## Building A Docker image file with sbt-pack\n\nBuilding a docker image of Scala application becomes easier with sbt-pack: \n\n**build.sbt**\n```scala\nenablePlugins(PackPlugin)\nname := \"myapp\"\npackMain := Map(\"myapp\"-\u003e\"org.yourdomain.MyApp\")\n```\n\n**Dockerfile**\n```\n# Using JDK17 from Amazon Corretto\nFROM amazoncorretto:17\n\nCOPY target/pack /srv/myapp\n\n# Using a non-privileged user:\nUSER nobody\nWORKDIR /srv/myapp\n\nENTRYPOINT [\"sh\", \"./bin/myapp\"]\n```\n\nThen you can build a docker image of your project:\n```\n$ sbt pack\n$ docker build -t your_org/myapp:latest .\n\n\n# Run your application with Docker\n$ docker run -it --rm your_org/myapp:latest (command line arg...)\n```\n\n\t\n### For developers\n\nTo test sbt-pack plugin, run\n\n    $ ./sbt scripted\n\nRun a single test project, e.g., `src/sbt-test/sbt-pack/multi-module`:\n\n    $ ./sbt \"scripted sbt-pack/multi-module\"\n\nFor releasing:\n\n```\n$ ./sbt\n\u003e scripted\n\u003e publishSigned\n\u003e sonatypeBundleRelease\n```\n","funding_links":[],"categories":["SOURCE","Table of Contents","Sbt plugins"],"sub_categories":["Sbt plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxerial%2Fsbt-pack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxerial%2Fsbt-pack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxerial%2Fsbt-pack/lists"}