Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Shrink Guava using Gradle
apply plugin: 'base'
buildscript {
repositories {
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.11'
configurations {
String getClassesJar(String platform) {
def javaHome ='java.home'
switch (platform.replaceAll(' ', '').toLowerCase()) {
case ~/.*osx.*/:
// java6 only
return "$javaHome/../Classes/classes.jar"
case ~/.*linux.*/:
case ~/.*darwin.*/:
case ~/.*win.*/:
return "$javaHome/bin/rt.jar"
default: throw new GradleException('unable to determine java runtime classes!')
def guavaVersion = '17.0'
def classesJar = files(getClassesJar(['']))
dependencies {
injar "${guavaVersion}"
libjar ''
libjar classesJar
* Run proguard to shrink guava to only include the stuff we specify and its dependencies.
task createCustomGuava(type: proguard.gradle.ProGuardTask) {
injars configurations.injar.files
libraryjars configurations.libjar.files
outjars file("build/libs/guava_${guavaVersion}_base.jar")
configuration "guava.proguard"
artifacts {
'default' (file: createCustomGuava.outputs.files.singleFile, builtBy: createCustomGuava)
-keep public class** {
public *;
Copy link

ligi commented Dec 2, 2014

as three are no pull requests for gitsts I pushed my changes to this repo:
this was a nice start but was not working on my ubuntu or a friends mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment