forked from softprops/assembly-sbt
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assembly: Added keepRules which runs on the final jar
This allows users of this lib/plugin to keep only files from libraries they use in their project without specifying them in zap
- Loading branch information
Showing
11 changed files
with
130 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
lazy val scala212 = "2.12.15" | ||
lazy val scala213 = "2.13.7" | ||
|
||
scalaVersion := scala212 | ||
crossScalaVersions := List(scala212, scala213) | ||
|
||
lazy val keeprules = (project in file(".")). | ||
settings( | ||
version := "0.1", | ||
assembly / assemblyJarName := "foo.jar", | ||
libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.8.1", | ||
assembly / assemblyKeepRules := Seq("keep.**"), | ||
TaskKey[Unit]("check") := { | ||
IO.withTemporaryDirectory { dir ⇒ | ||
IO.unzip(crossTarget.value / "foo.jar", dir) | ||
mustNotExist(dir / "removed" / "ShadeClass.class") | ||
mustNotExist(dir / "removed" / "ShadePackage.class") | ||
mustExist(dir / "keep" / "Keeped.class") | ||
mustExist(dir / "org" / "apache" / "commons" / "lang3" / "time" / "TimeZones.class") | ||
mustNotExist(dir / "org" / "apache" / "commons" / "lang3" / "time" / "DateParser.class") | ||
} | ||
}) | ||
|
||
def mustNotExist(f: File): Unit = { | ||
if (f.exists) sys.error("file" + f + " exists!") | ||
} | ||
def mustExist(f: File): Unit = { | ||
if (!f.exists) sys.error("file" + f + " does not exist!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
val pluginVersion = System.getProperty("plugin.version") | ||
if(pluginVersion == null) | ||
throw new RuntimeException("""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
else addSbtPlugin("com.eed3si9n" % "sbt-assembly" % pluginVersion) | ||
} |
7 changes: 7 additions & 0 deletions
7
src/sbt-test/shading/keeprules/src/main/scala/keep/Keeped.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package keep | ||
|
||
class Keeped { | ||
def main(args: Array[String]): Unit = { | ||
val myUsedObject = org.apache.commons.lang3.time.TimeZones.GMT_ID | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/shading/keeprules/src/main/scala/removed/ShadeClass.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package removed | ||
|
||
class ShadeClass |
3 changes: 3 additions & 0 deletions
3
src/sbt-test/shading/keeprules/src/main/scala/removed/ShadePackage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package removed | ||
|
||
class ShadePackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# check if the file gets created | ||
> +assembly | ||
$ exists target/scala-2.12/foo.jar | ||
$ exists target/scala-2.13/foo.jar | ||
|
||
# check if it says hello | ||
> +check |