sbt plugin for running ProGuard. This plugin requires sbt 1.0.
Add plugin to project/plugins.sbt
. For example:
addSbtPlugin("com.github.sbt" % "sbt-proguard" % "{version}")
See released versions.
Note: earlier versions of sbt-proguard used the "com.typesafe.sbt"
or "com.lightbend.sbt"
organization.
A simple build.sbt
with settings to configure sbt-proguard:
enablePlugins(SbtProguard)
proguardOptions in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")
proguardOptions in Proguard += ProguardOptions.keepMain("some.MainClass")
Run proguard at the sbt shell with:
proguard
In your build.sbt
:
Proguard/proguardVersion := "6.2.2"
Or interactively in the sbt shell:
set myProject/Proguard/proguardVersion := "6.2.2"
show myProject/Proguard/proguardVersion
Available proguard versions: https://github.com/Guardsquare/proguard/releases
Proguard supports file filtering for inputs, libraries, and outputs. In
sbt-proguard there are File => Option[String]
settings for adding filters to
files.
For example, to add a !META-INF/**
filter to just the scala-library jar:
proguardInputFilter in Proguard := { file =>
file.name match {
case "scala-library.jar" => Some("!META-INF/**")
case _ => None
}
}
which will create the following proguard configuration:
-injars "/path/to/scala-library.jar"(!META-INF/**)
There are corresponding settings for libraries and outputs: proguardLibraryFilter
and
proguardOutputFilter
.
For more advanced usage the proguardFilteredInputs
, proguardFilteredLibraries
, and
proguardFilteredOutputs
settings can be set directly.
If the same path exists in multiple inputs then proguard will throw an error.
The conflicting paths can be resolved using file filters, as described above,
but this is not always the most useful approach. For example, reference.conf
files for the Typesafe Config library need to be retained and not discarded.
The sbt-proguard plugin supports pre-merging inputs, similar to creating an assembly jar first. To enable this merging use:
proguardMerge in Proguard := true
Conflicting paths that are not identical will now fail at the merge stage. These conflicting paths can have merge strategies applied, similar to the sbt-assembly plugin.
Helper methods for creating common merges are available. These are:
discard
-- discard all matching entriesfirst
-- only keep the first entrylast
-- only keep the last entryrename
-- rename entries adding the name of the sourceappend
-- append entries together into one file
The paths matched against in these helpers are normalised to be separated by /
regardless of platform. Paths can be matched exactly with a string or with a
regular expression.
The default strategy is to only discard META-INF/MANIFEST.MF
. This same
strategy could be added with:
proguardMergeStrategies in Proguard += ProguardMerge.discard("META-INF/MANIFEST.MF")
Or all META-INF
contents could be discarded with a regular expression:
proguardMergeStrategies in Proguard += ProguardMerge.discard("META-INF/.*".r)
To concatenate all reference.conf
files together use:
proguardMergeStrategies in Proguard += ProguardMerge.append("reference.conf")
To discard all .html
and .txt
files you may use two strategies together:
proguardMergeStrategies in Proguard ++= Seq(
ProguardMerge.discard("\\.html$".r),
ProguardMerge.discard("\\.txt$".r)
)
Completely custom merge strategies can also be created. See the plugin source code for how this could be done.
There are some runnable sample projects included as sbt scripted tests.
Contributions via GitHub pull requests are gladly accepted from their original author. Before we can accept pull requests, you will need to agree to the Lightbend Contributor License Agreement online, using your GitHub account.
ProGuard is licensed under the GNU General Public License. sbt and sbt scripts are included in a special exception to the GPL licensing.
The code for this sbt plugin is licensed under the Apache 2.0 License.