From 361224a6202856bc2e572df811d0e6a1f1efda98 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sun, 6 Jun 2021 02:25:24 -0400 Subject: [PATCH] Drop default testing on assembly --- README.md | 46 +++++++++++-------- .../scala/sbtassembly/AssemblyPlugin.scala | 2 +- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 0d0a8c3e..aba49d43 100644 --- a/README.md +++ b/README.md @@ -46,19 +46,13 @@ ThisBuild / version := "0.1.0-SNAPSHOT" ThisBuild / organization := "com.example" ThisBuild / scalaVersion := "2.13.6" -lazy val commonSettings = Seq( - Compile / assembly / test := {} -) - lazy val app = (project in file("app")) - .settings(commonSettings) .settings( Compile / assembly / mainClass := Some("com.example.Main"), // more settings here ... ) lazy val utils = (project in file("utils")) - .settings(commonSettings) .settings( Compile / assembly / assemblyJarName := "utils.jar", // more settings here ... @@ -78,7 +72,7 @@ single JAR file: `target/scala_X.X.X/projectname-assembly-X.X.X.jar`. If you specify a `mainClass in assembly` in build.sbt (or just let it autodetect one) then you'll end up with a fully executable JAR, ready to rock. -Here is the list of the keys you can rewire for `assembly` task. +Here is the list of the keys you can rewire for `assembly` task. assemblyJarName test mainClass assemblyOutputPath assemblyMergeStrategy assemblyOption @@ -87,29 +81,45 @@ Here is the list of the keys you can rewire for `assembly` task. For example the name of the jar can be set as follows in build.sbt: ```scala -Compile / assembly / assemblyJarName := "something.jar" +lazy val app = (project in file("app")) + .settings( + Compile / assembly / assemblyJarName := "something.jar", + // more settings here ... + ) ``` -To skip the test during assembly, +To set an explicit main class, ```scala -Compile / assembly / test := {} +lazy val app = (project in file("app")) + .settings( + Compile / assembly / mainClass := Some("com.example.Main"), + // more settings here ... + ) ``` -To set an explicit main class, +To run the test during assembly, ```scala -Compile / assembly / mainClass := Some("com.example.Main") +lazy val app = (project in file("app")) + .settings( + Compile / assembly / test := (Test / test).value, + // more settings here ... + ) ``` Excluding an explicit main class from your assembly requires something a little bit different though ``` -Compile / assembly / packageOptions ~= { pos => - pos.filterNot { po => - po.isInstanceOf[Package.MainClass] - } -} +lazy val app = (project in file("app")) + .settings( + Compile / assembly / packageOptions ~= { pos => + pos.filterNot { po => + po.isInstanceOf[Package.MainClass] + } + }, + // more settings here ... + ) ``` ### Merge Strategy @@ -233,7 +243,7 @@ To see the verbose output for shading: #### Scala libraries Scala classes contain an annotation which, among other things, contain all symbols referenced in that class. As of sbt-assembly XXX the rename rules -will be applied to these annotations as well which makes it possible to compile or reflect against a shaded library. +will be applied to these annotations as well which makes it possible to compile or reflect against a shaded library. This is currently limited to renaming packages. Renaming class names will not work and cause compiler errors when compiling against the shaded library. diff --git a/src/main/scala/sbtassembly/AssemblyPlugin.scala b/src/main/scala/sbtassembly/AssemblyPlugin.scala index 0337c591..287683f4 100644 --- a/src/main/scala/sbtassembly/AssemblyPlugin.scala +++ b/src/main/scala/sbtassembly/AssemblyPlugin.scala @@ -69,7 +69,7 @@ object AssemblyPlugin extends sbt.AutoPlugin { assembledMappings in assemblyPackageDependency := Assembly.assembledMappingsTask(assemblyPackageDependency).value, // test - test in assembly := (test in Test).value, + test in assembly := { () }, test in assemblyPackageScala := (test in assembly).value, test in assemblyPackageDependency := (test in assembly).value,