Skip to content

Instantly share code, notes, and snippets.

@devisnik
Last active September 5, 2017 16:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devisnik/e54ea0a629adc82bcfa0 to your computer and use it in GitHub Desktop.
Save devisnik/e54ea0a629adc82bcfa0 to your computer and use it in GitHub Desktop.
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