Skip to content

Commit

Permalink
Merge pull request #721 from mikebridge/master
Browse files Browse the repository at this point in the history
Add Proguard example to Custom Package Format documentation
  • Loading branch information
muuki88 committed Jan 6, 2016
2 parents 409497a + 588e826 commit 21ad738
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/sphinx/topics/custom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ SBT Assembly
| Create a fat-jar with sbt-assembly in order to deliver a single,
| self-containing jar as a package instead of the default lib/ structure
First add the sbt-assembly plugin to your `plugins.sbt` file.
First add the sbt-assembly plugin to your ``plugins.sbt`` file.

.. code-block:: scala
Expand Down Expand Up @@ -53,6 +53,64 @@ contains the assembled jar. This is what the final ``build.sbt`` should contain:
// the bash scripts classpath only needs the fat jar
scriptClasspath := Seq( (jarName in assembly).value )
Proguard
-------------------

**Main Goal**

| Create a package that contains a single fat-jar that has been shrunken / optimized / obfuscated with `proguard <http://proguard.sourceforge.net/>`_.
First add the `sbt-proguard <https://github.com/sbt/sbt-proguard>`_ plugin to
the ``plugins.sbt`` file:

.. code-block:: scala
addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")
Then configure the proguard options in ``build.sbt``:

.. code-block:: scala
import com.typesafe.sbt.SbtProguard.ProguardKeys
// initialize the proguard settings
proguardSettings
// to configure proguard for scala, see
// http://proguard.sourceforge.net/manual/examples.html#scala
ProguardKeys.options in Proguard ++= Seq(
"--dontwarn scala.**",
"--dontwarn ch.qos.**"
// ...
)
// specify the entry point for a standalone app
ProguardKeys.options in Proguard += ProguardOptions.keepMain("com.example.Main")
// Java 8 requires a newer version of proguard than sbt-proguard's default
ProguardKeys.proguardVersion in Proguard := "5.2.1"
// filter out jar files from the list of generated files, while
// keeping non-jar output such as generated launch scripts
mappings in Universal := (mappings in Universal).value.
filter {
case (file, name) => ! name.endsWith(".jar")
}
// ... and then append the jar file emitted from the proguard task to
// the file list
mappings in Universal ++= (ProguardKeys.proguard in Proguard).
value.map(jar => jar -> ("lib/" +jar.getName))
// point the classpath to the output from the proguard task
scriptClasspath := (ProguardKeys.proguard in Proguard).value.map(jar => jar.getName)
Now when you package your project using a command such as ``sbt universal:package-zip-tarball``,
it will include fat jar that has been created by proguard rather than the normal
output in ``/lib``.


Multi Module Builds
-------------------
Expand Down

0 comments on commit 21ad738

Please sign in to comment.