Home | History | Annotate | Download | only in gradle
      1 //
      2 // This Gradle build file illustrates how to process applets.
      3 // Usage:
      4 //     gradle -b applets.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 
     34     // Save the obfuscation mapping to a file, so you can de-obfuscate any stack
     35     // traces later on. Keep a fixed source file attribute and all line number
     36     // tables to get line numbers in the stack traces.
     37     // You can comment this out if you're not interested in stack traces.
     38 
     39     printmapping 'out.map'
     40     renamesourcefileattribute 'SourceFile'
     41     keepattributes 'SourceFile,LineNumberTable'
     42 
     43     // Preserve all annotations.
     44 
     45     keepattributes '*Annotation*'
     46 
     47     // You can print out the seeds that are matching the keep options below.
     48 
     49     //printseeds 'out.seeds'
     50 
     51     // Preserve all public applets.
     52 
     53     keep 'public class * extends java.applet.Applet'
     54 
     55     // Preserve all native method names and the names of their classes.
     56 
     57     keepclasseswithmembernames 'class * { \
     58         native <methods>; \
     59     }'
     60 
     61     // Preserve the special static methods that are required in all enumeration
     62     // classes.
     63 
     64     keepclassmembers 'class * extends java.lang.Enum { \
     65         public static **[] values(); \
     66         public static ** valueOf(java.lang.String); \
     67     }'
     68 
     69     // Explicitly preserve all serialization members. The Serializable interface
     70     // is only a marker interface, so it wouldn't save them.
     71     // You can comment this out if your library doesn't use serialization.
     72     // If your code contains serializable classes that have to be backward
     73     // compatible, please refer to the manual.
     74 
     75     keepclassmembers 'class * implements java.io.Serializable { \
     76         static final long serialVersionUID; \
     77         static final java.io.ObjectStreamField[] serialPersistentFields; \
     78         private void writeObject(java.io.ObjectOutputStream); \
     79         private void readObject(java.io.ObjectInputStream); \
     80         java.lang.Object writeReplace(); \
     81         java.lang.Object readResolve(); \
     82     }'
     83 
     84     // Your application may contain more items that need to be preserved;
     85     // typically classes that are dynamically created using Class.forName:
     86 
     87     // keep 'public class mypackage.MyClass'
     88     // keep 'public interface mypackage.MyInterface'
     89     // keep 'public class * implements mypackage.MyInterface'
     90 }
     91