Skip to content

Commit

Permalink
Drop default testing on assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Jun 6, 2021
1 parent 5dda244 commit 361224a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
46 changes: 28 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/sbtassembly/AssemblyPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down

0 comments on commit 361224a

Please sign in to comment.