1 <!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2 <html> 3 <head> 4 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 5 <meta http-equiv="content-style-type" content="text/css"> 6 <link rel="stylesheet" type="text/css" href="style.css"> 7 <title>Gradle Task</title> 8 <script type="text/javascript" language="JavaScript"> 9 <!-- 10 if (window.self==window.top) { 11 history.go(-1); 12 window.top.location.replace("../index.html#"+window.location.pathname+window.location.hash); 13 } else { 14 var hash="#"+window.location.pathname.replace(window.top.location.pathname.replace("index.html", ""), ""); 15 if (window.top.location.hash!=hash) 16 window.top.location.hash=hash; 17 } 18 //--> 19 </script> 20 </head> 21 <body> 22 23 <h2>Gradle Task</h2> 24 25 <b>ProGuard</b> can be run as a task in the Java-based build tool Gradle 26 (version 1.3 or higher). 27 <p> 28 29 Before you can use the <code>proguard</code> task, you have to make sure 30 Gradle can find it in its class path at build time. One way is to add the 31 following line to your <code>build.gradle</code> file: 32 <p> 33 34 <pre> 35 buildscript { 36 repositories { 37 flatDir dirs: '/usr/local/java/proguard/lib' 38 } 39 dependencies { 40 classpath ':proguard' 41 } 42 } 43 </pre> 44 <p> 45 46 Please make sure the class path is set correctly for your system. 47 <p> 48 49 You can then define a task: 50 <p> 51 <pre> 52 task myProguardTask(type: proguard.gradle.ProGuardTask) { 53 ..... 54 } 55 </pre> 56 <p> 57 58 The embedded configuration is much like a standard ProGuard configuration. 59 Notable similarities and differences: 60 <ul> 61 <li>Like in ProGuard-style configurations, we're using all lower-case names 62 for the settings.</li> 63 <li>The options don't have a dash as prefix.</li> 64 <li>Arguments typically have quotes.</li> 65 <li>Some settings are specified as named arguments.</li> 66 </ul> 67 <p> 68 You can find some sample build files in the <code>examples/gradle</code> 69 directory of the ProGuard distribution. 70 <p> 71 If you prefer a more verbose configuration derived from the Ant task, you can 72 import the Ant task as a <a href="#anttask">Gradle task</a>. 73 74 <h2><a name="proguard">Settings</a></h2> 75 76 The ProGuard task supports the following settings in its closure: 77 78 <dl> 79 80 <dt><a name="configuration_attribute"><code><b>configuration</b></code></a> 81 <a href="#file"><i>files</i></a></dt> 82 <dd>Read and merge options from the given ProGuard-style configuration 83 files. The files are resolved and parsed lazily, during the execution 84 phase.</dd> 85 86 <dt><a href="usage.html#injars"><code><b>injars</b></code></a> 87 <a href="#classpath"><i>class_path</i></a></dt> 88 <dd>Specifies the program jars (or wars, ears, zips, or directories). The files 89 are resolved and read lazily, during the execution phase.</dd> 90 91 <dt><a href="usage.html#outjars"><code><b>outjars</b></code></a> 92 <a href="#classpath"><i>class_path</i></a></dt> 93 <dd>Specifies the names of the output jars (or wars, ears, zips, or 94 directories). The files are resolved and written lazily, during the 95 execution phase.</dd> 96 97 <dt><a href="usage.html#libraryjars"><code><b>libraryjars</b></code></a> 98 <a href="#classpath"><i>class_path</i></a></dt> 99 <dd>Specifies the library jars (or wars, ears, zips, or directories). The files 100 are resolved and read lazily, during the execution phase.</dd> 101 102 <dt><a href="usage.html#skipnonpubliclibraryclasses"><code><b>skipnonpubliclibraryclasses</b></code></a></dt> 103 <dd>Ignore non-public library classes.</dd> 104 105 <dt><a href="usage.html#dontskipnonpubliclibraryclassmembers"><code><b>dontskipnonpubliclibraryclassmembers</b></code></a></dt> 106 <dd>Don't ignore package visible library class members.</dd> 107 108 <dt><a href="usage.html#keepdirectories"><code><b>keepdirectories</b></code></a> 109 ['<a href="usage.html#filefilters"><i>directory_filter</i></a>']</dt> 110 <dd>Keep the specified directories in the output jars (or wars, ears, zips, 111 or directories).</dd> 112 113 <dt><a href="usage.html#target"><code><b>target</b></code></a> 114 '<i>version</i>'</dt> 115 <dd>Set the given version number in the processed classes.</dd> 116 117 <dt><a href="usage.html#forceprocessing"><code><b>forceprocessing</b></code></a></dt> 118 <dd>Process the input, even if the output seems up to date.</dd> 119 120 <dt><a href="usage.html#keep"><code><b>keep</b></code></a> 121 [<a href="#keepmodifier"><i>modifier</i>,...</a>] 122 <a href="#classspecification"><i>class_specification</i></a></dt> 123 <dd>Preserve the specified classes <i>and</i> class members.</dd> 124 125 <dt><a href="usage.html#keepclassmembers"><code><b>keepclassmembers</b></code></a> 126 [<a href="#keepmodifier"><i>modifier</i>,...</a>] 127 <a href="#classspecification"><i>class_specification</i></a></dt> 128 <dd>Preserve the specified class members, if their classes are preserved as 129 well.</dd> 130 131 <dt><a href="usage.html#keepclasseswithmembers"><code><b>keepclasseswithmembers</b></code></a> 132 [<a href="#keepmodifier"><i>modifier</i>,...</a>] 133 <a href="#classspecification"><i>class_specification</i></a></dt> 134 <dd>Preserve the specified classes <i>and</i> class members, if all of the 135 specified class members are present.</dd> 136 137 <dt><a href="usage.html#keepnames"><code><b>keepnames</b></code></a> 138 <a href="#classspecification"><i>class_specification</i></a></dt> 139 <dd>Preserve the names of the specified classes <i>and</i> class members (if 140 they aren't removed in the shrinking step).</dd> 141 142 <dt><a href="usage.html#keepclassmembernames"><code><b>keepclassmembernames</b></code></a> 143 <a href="#classspecification"><i>class_specification</i></a></dt> 144 <dd>Preserve the names of the specified class members (if they aren't removed 145 in the shrinking step).</dd> 146 147 <dt><a href="usage.html#keepclasseswithmembernames"><code><b>keepclasseswithmembernames</b></code></a> 148 <a href="#classspecification"><i>class_specification</i></a></dt> 149 <dd>Preserve the names of the specified classes <i>and</i> class members, if 150 all of the specified class members are present (after the shrinking 151 step).</dd> 152 153 <dt><a href="usage.html#printseeds"><code><b>printseeds</b></code></a> 154 [<a href="#file"><i>file</i></a>]</dt> 155 <dd>List classes and class members matched by the various <code>keep</code> 156 commands, to the standard output or to the given file.</dd> 157 158 <dt><a href="usage.html#dontshrink"><code><b>dontshrink</b></code></a></dt> 159 <dd>Don't shrink the input class files.</dd> 160 161 <dt><a href="usage.html#printusage"><code><b>printusage</b></code></a> 162 [<a href="#file"><i>file</i></a>]</dt> 163 <dd>List dead code of the input class files, to the standard output or to the 164 given file.</dd> 165 166 <dt><a href="usage.html#whyareyoukeeping"><code><b>whyareyoukeeping</b></code></a> 167 <a href="#classspecification"><i>class_specification</i></a></dt> 168 <dd>Print details on why the given classes and class members are being kept in 169 the shrinking step.</dd> 170 171 <dt><a href="usage.html#dontoptimize"><code><b>dontoptimize</b></code></a></dt> 172 <dd>Don't optimize the input class files.</dd> 173 174 <dt><a href="usage.html#optimizations"><code><b>optimizations</b></code></a> '<a href="optimizations.html"><i>optimization_filter</i></a>'</dt> 175 <dd>Perform only the specified optimizations.</dd> 176 177 <dt><a href="usage.html#optimizationpasses"><code><b>optimizationpasses</b></code></a> 178 <i>n</i></dt> 179 <dd>The number of optimization passes to be performed.</dd> 180 181 <dt><a href="usage.html#assumenosideeffects"><code><b>assumenosideeffects</b></code></a> 182 <a href="#classspecification"><i>class_specification</i></a></dt> 183 <dd>Assume that the specified methods don't have any side effects, while 184 optimizing. <i>Only use this option if you know what you're 185 doing!</i></dd> 186 187 <dt><a href="usage.html#allowaccessmodification"><code><b>allowaccessmodification</b></code></a></dt> 188 <dd>Allow the access modifiers of classes and class members to be modified, 189 while optimizing.</dd> 190 191 <dt><a href="usage.html#mergeinterfacesaggressively"><code><b>mergeinterfacesaggressively</b></code></a></dt> 192 <dd>Allow any interfaces to be merged, while optimizing.</dd> 193 194 <dt><a href="usage.html#dontobfuscate"><code><b>dontobfuscate</b></code></a></dt> 195 <dd>Don't obfuscate the input class files.</dd> 196 197 <dt><a href="usage.html#printmapping"><code><b>printmapping</b></code></a> 198 [<a href="#file"><i>file</i></a>]</dt> 199 <dd>Print the mapping from old names to new names for classes and class members 200 that have been renamed, to the standard output or to the given file.</dd> 201 202 <dt><a href="usage.html#applymapping"><code><b>applymapping</b></code></a> 203 <a href="#file"><i>file</i></a></dt> 204 <dd>Reuse the given mapping, for incremental obfuscation.</dd> 205 206 <dt><a href="usage.html#obfuscationdictionary"><code><b>obfuscationdictionary</b></code></a> 207 <a href="#file"><i>file</i></a></dt> 208 <dd>Use the words in the given text file as obfuscated field names and method 209 names.</dd> 210 211 <dt><a href="usage.html#classobfuscationdictionary"><code><b>classobfuscationdictionary</b></code></a> 212 <a href="#file"><i>file</i></a></dt> 213 <dd>Use the words in the given text file as obfuscated class names.</dd> 214 215 <dt><a href="usage.html#packageobfuscationdictionary"><code><b>packageobfuscationdictionary</b></code></a> 216 <a href="#file"><i>file</i></a></dt> 217 <dd>Use the words in the given text file as obfuscated package names.</dd> 218 219 <dt><a href="usage.html#overloadaggressively"><code><b>overloadaggressively</b></code></a></dt> 220 <dd>Apply aggressive overloading while obfuscating.</dd> 221 222 <dt><a href="usage.html#useuniqueclassmembernames"><code><b>useuniqueclassmembernames</b></code></a></dt> 223 <dd>Ensure uniform obfuscated class member names for subsequent incremental 224 obfuscation.</dd> 225 226 <dt><a href="usage.html#dontusemixedcaseclassnames"><code><b>dontusemixedcaseclassnames</b></code></a></dt> 227 <dd>Don't generate mixed-case class names while obfuscating.</dd> 228 229 <dt><a href="usage.html#keeppackagenames"><code><b>keeppackagenames</b></code></a> ['<a href="usage.html#filters"><i>package_filter</i></a>']</dt> 230 <dd>Keep the specified package names from being obfuscated. If no name is 231 given, all package names are preserved.</dd> 232 233 <dt><a href="usage.html#flattenpackagehierarchy"><code><b>flattenpackagehierarchy</b></code></a> 234 '<i>package_name</i>'</dt> 235 <dd>Repackage all packages that are renamed into the single given parent 236 package.</dd> 237 238 <dt><a href="usage.html#repackageclasses"><code><b>repackageclasses</b></code></a> 239 ['<i>package_name</i>']</dt> 240 <dd>Repackage all class files that are renamed into the single given 241 package.</dd> 242 243 <dt><a href="usage.html#keepattributes"><code><b>keepattributes</b></code></a> ['<a href="usage.html#filters"><i>attribute_filter</i></a>']</dt> 244 <dd>Preserve the specified optional Java bytecode attributes, with optional 245 wildcards. If no name is given, all attributes are preserved.</dd> 246 247 <dt><a href="usage.html#keepparameternames"><code><b>keepparameternames</b></code></a></dt> 248 <dd>Keep the parameter names and types of methods that are kept.</dd> 249 250 <dt><a href="usage.html#renamesourcefileattribute"><code><b>renamesourcefileattribute</b></code></a> 251 ['<i>string</i>']</dt> 252 <dd>Put the given constant string in the <code>SourceFile</code> 253 attributes.</dd> 254 255 <dt><a href="usage.html#adaptclassstrings"><code><b>adaptclassstrings</b></code></a> 256 ['<a href="usage.html#filters"><i>class_filter</i></a>']</dt> 257 <dd>Adapt string constants in the specified classes, based on the obfuscated 258 names of any corresponding classes.</dd> 259 260 <dt><a href="usage.html#adaptresourcefilenames"><code><b>adaptresourcefilenames</b></code></a> 261 ['<a href="usage.html#filefilters"><i>file_filter</i></a>']</dt> 262 <dd>Rename the specified resource files, based on the obfuscated names of the 263 corresponding class files.</dd> 264 265 <dt><a href="usage.html#adaptresourcefilecontents"><code><b>adaptresourcefilecontents</b></code></a> 266 ['<a href="usage.html#filefilters"><i>file_filter</i></a>']</dt> 267 <dd>Update the contents of the specified resource files, based on the 268 obfuscated names of the processed classes.</dd> 269 270 <dt><a href="usage.html#dontpreverify"><code><b>dontpreverify</b></code></a></dt> 271 <dd>Don't preverify the processed class files if they are targeted at Java Micro 272 Edition or at Java 6 or higher.</dd> 273 274 <dt><a href="usage.html#microedition"><code><b>microedition</b></code></a></dt> 275 <dd>Target the processed class files at Java Micro Edition.</dd> 276 277 <dt><a href="usage.html#verbose"><code><b>verbose</b></code></a></dt> 278 <dd>Write out some more information during processing.</dd> 279 280 <dt><a href="usage.html#dontnote"><code><b>dontnote</b></code></a> '<a href="usage.html#filters"><i>class_filter</i></a>'</dt> 281 <dd>Don't print notes about classes matching the specified class name 282 filter.</dd> 283 284 <dt><a href="usage.html#dontwarn"><code><b>dontwarn</b></code></a> '<a href="usage.html#filters"><i>class_filter</i></a>'</dt> 285 <dd>Don't print warnings about classes matching the specified class name 286 filter. <i>Only use this option if you know what you're doing!</i></dd> 287 288 <dt><a href="usage.html#ignorewarnings"><code><b>ignorewarnings</b></code></a></dt> 289 <dd>Print warnings about unresolved references, but continue processing 290 anyhow. <i>Only use this option if you know what you're doing!</i></dd> 291 292 <dt><a href="usage.html#printconfiguration"><code><b>printconfiguration</b></code></a> 293 [<a href="#file"><i>file</i></a>]</dt> 294 <dd>Write out the entire configuration in traditional ProGuard style, to the 295 standard output or to the given file. Useful to replace unreadable 296 XML configurations.</dd> 297 298 <dt><a href="usage.html#dump"><code><b>dump</b></code></a> 299 [<a href="#file"><i>file</i></a>]</dt> 300 <dd>Write out the internal structure of the processed class files, to the 301 standard output or to the given file.</dd> 302 303 </dl> 304 305 <h2><a name="classpath">Class Paths</a></h2> 306 307 Class paths are specified as Gradle file collections, which means they can be 308 specified as simple strings, with <code>files(Object)</code>, etc. 309 <p> 310 In addition, they can have ProGuard-style filters, specified as 311 comma-separated named arguments after the file: 312 313 <dl> 314 315 <dt><code><b>filter:</b></code> 316 '<a href="usage.html#filefilters"><i>file_filter</i></a>'</dt> 317 <dd>An optional filter for all class file names and resource file names that 318 are encountered.</dd> 319 320 <dt><code><b>jarfilter:</b></code> 321 '<a href="usage.html#filefilters"><i>file_filter</i></a>'</dt> 322 <dd>An optional filter for all jar names that are encountered.</dd> 323 324 <dt><code><b>warfilter:</b></code> 325 '<a href="usage.html#filefilters"><i>file_filter</i></a>'</dt> 326 <dd>An optional filter for all war names that are encountered.</dd> 327 328 <dt><code><b>earfilter:</b></code> 329 '<a href="usage.html#filefilters"><i>file_filter</i></a>'</dt> 330 <dd>An optional filter for all ear names that are encountered.</dd> 331 332 <dt><code><b>zipfilter:</b></code> 333 '<a href="usage.html#filefilters"><i>file_filter</i></a>'</dt> 334 <dd>An optional filter for all zip names that are encountered.</dd> 335 336 </dl> 337 338 <h2><a name="file">Files</a></h2> 339 340 Files are specified as Gradle files, which means they can be specified 341 as simple strings, as File instances, with <code>file(Object)</code>, etc. 342 <p> 343 In Gradle, file names (any strings really) in double quotes can contain 344 properties or code inside <code>${...}</code>. These are automatically 345 expanded. 346 <p> 347 For example, <code>"${System.getProperty('java.home')}/lib/rt.jar"</code> is 348 expanded to something like <code>'/usr/local/java/jdk/jre/lib/rt.jar'</code>. 349 Similarly, <code>System.getProperty('user.home')</code> is expanded to the 350 user's home directory, and <code>System.getProperty('user.dir')</code> is 351 expanded to the current working directory. 352 353 <h2><a name="keepmodifier">Keep Modifiers</a></h2> 354 355 The keep settings can have the following named arguments that modify their 356 behaviors: 357 358 <dl> 359 360 <dt><a href="usage.html#allowshrinking"><code><b>allowshrinking:</b></code></a> 361 <i>boolean</i> 362 (default = false)</dt> 363 <dd>Specifies whether the entry points specified in the keep tag may be 364 shrunk.</dd> 365 366 <dt><a href="usage.html#allowoptimization"><code><b>allowoptimization:</b></code></a> 367 <i>boolean</i> 368 (default = false)</dt> 369 <dd>Specifies whether the entry points specified in the keep tag may be 370 optimized.</dd> 371 372 <dt><a href="usage.html#allowobfuscation"><code><b>allowobfuscation:</b></code></a> 373 <i>boolean</i> 374 (default = false)</dt> 375 <dd>Specifies whether the entry points specified in the keep tag may be 376 obfuscated.</dd> 377 378 </dl> 379 380 Names arguments are comma-separated, as usual. 381 382 <h2><a name="classspecification">Class Specifications</a></h2> 383 384 A class specification is a template of classes and class members (fields and methods). There are two alternative ways to specify such a template: 385 386 <ol> 387 <li>As a string containing a ProGuard-style class specification. This is the 388 most compact and most readable way. The specification looks like a Java 389 declaration of a class with fields and methods. For example: 390 <pre> 391 keep 'public class mypackage.MyMainClass { \ 392 public static void main(java.lang.String[]); \ 393 }' 394 </pre></li> 395 <li>As a Gradle-style setting: a method calls with named arguments and a 396 closure. This is more verbose, but it might be useful for programmatic 397 specifications. For example: 398 <pre> 399 keep access: 'public', 400 name: 'mypackage.MyMainClass', { 401 method access: 'public static', 402 type: 'void', 403 name: 'main', 404 parameters: 'java.lang.String[]' 405 } 406 </pre></li> 407 </ol> 408 <p> 409 410 The <a href="usage.html#classspecification">ProGuard-style class 411 specification</a> is described on the traditional Usage page. 412 <p> 413 A Gradle-style class specification can have the following named arguments: 414 415 <dl> 416 417 <dt><code><b>access:</b></code> '<i>access_modifiers</i>'</dt> 418 <dd>The optional access modifiers of the class. Any space-separated list of 419 "public", "final", and "abstract", with optional negators "!".</dd> 420 421 <dt><code><b>annotation:</b></code> '<i>annotation_name</i>'</dt> 422 <dd>The optional fully qualified name of an annotation of the class, with 423 optional wildcards.</dd> 424 425 <dt><code><b>type:</b></code> '<i>type</i>'</dt> 426 <dd>The optional type of the class: one of "class", "interface", or 427 "!interface".</dd> 428 429 <dt><code><b>name:</b></code> '<i>class_name</i>'</dt> 430 <dd>The optional fully qualified name of the class, with optional 431 wildcards.</dd> 432 433 <dt><code><b>extendsannotation:</b></code> '<i>annotation_name</i>'</dt> 434 <dd>The optional fully qualified name of an annotation of the the class that 435 the specified classes must extend, with optional wildcards.</dd> 436 437 <dt><code><b>'extends':</b></code> '<i>class_name</i>'</dt> 438 <dd>The optional fully qualified name of the class the specified classes 439 must extend, with optional wildcards.</dd> 440 441 <dt><code><b>'implements':</b></code> '<i>class_name</i>'</dt> 442 <dd>The optional fully qualified name of the class the specified classes 443 must implement, with optional wildcards.</dd> 444 445 </dl> 446 447 The named arguments are optional. Without any arguments, there are no 448 constraints, so the settings match all classes. 449 <p> 450 451 <h3><a name="cl">Gradle-style Class Member Specifications</h3> 452 453 The closure of a Gradle-style class specification can specify class members 454 with these settings: 455 456 <dl> 457 458 <dt><code><b>field</b></code> <i>field_constraints</i></dt> 459 <dd>Specifies a field.</dd> 460 461 <dt><code><b>method</b></code> <i>method_constraints</i></dt> 462 <dd>Specifies a method.</dd> 463 464 <dt><code><b>constructor</b></code> <i>constructor_constraints</i></dt> 465 <dd>Specifies a constructor.</dd> 466 467 </dl> 468 469 A class member setting can have the following named arguments to express 470 constraints: 471 472 <dl> 473 474 <dt><code><b>access:</b></code> '<i>access_modifiers</i>'</dt> 475 <dd>The optional access modifiers of the class. Any space-separated list of 476 "public", "protected", "private", "static", etc., with optional negators 477 "!".</dd> 478 479 <dt><code><b>'annotation':</b></code> '<i>annotation_name</i>'</dt> 480 <dd>The optional fully qualified name of an annotation of the class member, 481 with optional wildcards.</dd> 482 483 <dt><code><b>type:</b></code> '<i>type</i>'</dt> 484 <dd>The optional fully qualified type of the class member, with optional 485 wildcards. Not applicable for constructors, but required for methods for 486 which the <code>parameters</code> argument is specified.</dd> 487 488 <dt><code><b>name:</b></code> '<i>name</i>'</dt> 489 <dd>The optional name of the class member, with optional wildcards. Not 490 applicable for constructors.</dd> 491 492 <dt><code><b>parameters:</b></code> '<i>parameters</i>'</dt> 493 <dd>The optional comma-separated list of fully qualified method parameters, 494 with optional wildcards. Not applicable for fields, but required for 495 constructors, and for methods for which the <code>type</code> argument is 496 specified.</dd> 497 498 </dl> 499 500 The named arguments are optional. Without any arguments, there are no 501 constraints, so the settings match all constructors, fields, or methods. 502 <p> 503 A class member setting doesn't have a closure. 504 505 <h2><a name="anttask">Alternative: imported Ant task</a></h2> 506 507 Instead of using the Gradle task, you could also integrate the Ant task in 508 your Gradle build file: 509 <p> 510 <pre> 511 ant.project.basedir = '../..' 512 513 ant.taskdef(resource: 'proguard/ant/task.properties', 514 classpath: '/usr/local/java/proguard/lib/proguard.jar') 515 </pre> 516 <p> 517 518 Gradle automatically converts the elements and attributes to Groovy methods, 519 so converting the configuration is essentially mechanical. The one-on-one 520 mapping can be useful, but the resulting configuration is more verbose. For 521 instance: 522 <pre> 523 task proguard << { 524 ant.proguard(printmapping: 'proguard.map', 525 overloadaggressively: 'on', 526 repackageclasses: '', 527 renamesourcefileattribute: 'SourceFile') { 528 529 injar(file: 'application.jar') 530 injar(file: 'gui.jar', filter: '!META-INF/**') 531 532 ..... 533 } 534 } 535 </pre> 536 <p> 537 538 <hr /> 539 <noscript><div><a target="_top" href="../index.html" class="button">Show menu</a></div></noscript> 540 <address> 541 Copyright © 2002-2013 542 <a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a>. 543 </address> 544 </body> 545 </html> 546