Last active
September 5, 2017 16:05
-
-
Save devisnik/e54ea0a629adc82bcfa0 to your computer and use it in GitHub Desktop.
Shrink Guava using Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-dontoptimize | |
-dontobfuscate | |
-keep public class com.google.common.base.** { | |
public *; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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