Home | History | Annotate | Download | only in gradle
      1 //
      2 // This Gradle build file illustrates how to process applications.
      3 // Usage:
      4 //     gradle -b applications.gradle proguard
      5 //
      6 
      7 // Tell Gradle where to find the ProGuard task.
      8 
      9 buildscript {
     10     repositories {
     11         flatDir dirs: '../../lib'
     12     }
     13     dependencies {
     14         classpath ':proguard'
     15     }
     16 }
     17 
     18 // Define a ProGuard task.
     19 
     20 task proguard(type: proguard.gradle.ProGuardTask) {
     21 
     22     // You should probably import a more compact ProGuard-style configuration
     23     // file for all static settings, but we're specifying them all here, for
     24     // the sake of the example.
     25     //configuration 'configuration.pro'
     26 
     27     // Specify the input jars, output jars, and library jars.
     28 
     29     injars  'in.jar'
     30     outjars 'out.jar'
     31 
     32     libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
     33     //libraryjars 'junit.jar'
     34     //libraryjars 'servlet.jar'
     35     //libraryjars 'jai_core.jar'
     36     //...
     37 
     38     // Save the obfuscation mapping to a file, so you can de-obfuscate any stack
     39     // traces later on. Keep a fixed source file attribute and all line number
     40     // tables to get line numbers in the stack traces.
     41     // You can comment this out if you're not interested in stack traces.
     42 
     43     printmapping 'out.map'
     44     renamesourcefileattribute 'SourceFile'
     45     keepattributes 'SourceFile,LineNumberTable'
     46 
     47     // Preserve all annotations.
     48 
     49     keepattributes '*Annotation*'
     50 
     51     // You can print out the seeds that are matching the keep options below.
     52 
     53     //printseeds 'out.seeds'
     54 
     55     // Preserve all public applications.
     56 
     57     keepclasseswithmembers 'public class * { \
     58         public static void main(java.lang.String[]); \
     59     }'
     60 
     61     // Preserve all native method names and the names of their classes.
     62 
     63     keepclasseswithmembernames includedescriptorclasses:true, 'class * { \
     64         native <methods>; \
     65     }'
     66 
     67     // Preserve the special static methods that are required in all enumeration
     68     // classes.
     69 
     70     keepclassmembers allowshrinking:true, 'enum * { \
     71         public static **[] values(); \
     72         public static ** valueOf(java.lang.String); \
     73     }'
     74 
     75     // Explicitly preserve all serialization members. The Serializable interface
     76     // is only a marker interface, so it wouldn't save them.
     77     // You can comment this out if your application doesn't use serialization.
     78     // If your code contains serializable classes that have to be backward 
     79     // compatible, please refer to the manual.
     80 
     81     keepclassmembers 'class * implements java.io.Serializable { \
     82         static final long serialVersionUID; \
     83         static final java.io.ObjectStreamField[] serialPersistentFields; \
     84         private void writeObject(java.io.ObjectOutputStream); \
     85         private void readObject(java.io.ObjectInputStream); \
     86         java.lang.Object writeReplace(); \
     87         java.lang.Object readResolve(); \
     88     }'
     89 
     90     // Your application may contain more items that need to be preserved; 
     91     // typically classes that are dynamically created using Class.forName:
     92 
     93     // keep 'public class mypackage.MyClass'
     94     // keep 'public interface mypackage.MyInterface'
     95     // keep 'public class * implements mypackage.MyInterface'
     96 }
     97