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