Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shrink Guava using Gradle
apply plugin: 'base'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.11'
}
}
configurations {
injar
libjar
}
String getClassesJar(String platform) {
def javaHome = System.properties.'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(System.properties['os.name']))
dependencies {
injar "com.google.guava:guava:${guavaVersion}"
libjar 'com.google.code.findbugs:jsr305:3.0.0'
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)
}
-dontoptimize
-dontobfuscate
-keep public class com.google.common.base.** {
public *;
}
@ligi
Copy link

ligi commented Dec 2, 2014

as three are no pull requests for gitsts I pushed my changes to this repo: https://github.com/ligi/shrinkGuava
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