<!doctype html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <meta http-equiv="content-style-type" content="text/css"> <link rel="stylesheet" type="text/css" href="style.css"> <title>Ant Task</title> </head> <body> <h2>Ant Task</h2> <b>ProGuard</b> can be run as a task in the Java-based build tool Ant (version 1.6.0 or higher). <p> Before you can use the <code>proguard</code> task, you have to tell Ant about this new task. The easiest way is to add the following line to your <code>build.xml</code> file: <p> <pre> <taskdef resource="proguard/ant/task.properties" classpath="/usr/local/java/proguard/lib/proguard.jar" /> </pre> <p> Please make sure the class path is set correctly for your system. <p> There are three ways to configure the ProGuard task: using an external configuration file, using embedded ProGuard configuration options, or using the equivalent XML configuration tags. These three ways can be combined, depending on practical circumstances and personal preference. <p> <h3>1. An external ProGuard configuration file</h3> The simplest way to use the ProGuard task in an Ant build file is to keep your ProGuard configuration file, and include it from Ant. You can include your ProGuard configuration file by setting the <a href="#configuration_attribute"><code>configuration</code></a> attribute of your <code>proguard</code> task. Your ant build file will then look like this: <p> <pre> <taskdef resource="proguard/ant/task.properties" classpath="/usr/local/java/proguard/lib/proguard.jar" /> <proguard configuration="myconfigfile.pro"/> </pre> <p> This is a convenient option if you prefer ProGuard's configuration style over XML, if you want to keep your build file small, or if you have to share your configuration with developers who don't use Ant. <p> <h3>2. Embedded ProGuard configuration options</h3> Instead of keeping an external ProGuard configuration file, you can also copy the contents of the file into the nested text of the <code>proguard</code> task (the PCDATA area). Your Ant build file will then look like this: <p> <pre> <taskdef resource="proguard/ant/task.properties" classpath="/usr/local/java/proguard/lib/proguard.jar" /> <proguard> -libraryjars ${java.home}/lib/rt.jar -injars in.jar -outjars out.jar -keepclasseswithmembers public class * { public static void main(java.lang.String[]); } </proguard> </pre> <p> Some minor syntactical changes are required in order to conform with the XML standard. <p> Firstly, the <code>#</code> character cannot be used for comments in an XML file. Comments must be enclosed by an opening <code><!--</code> and a closing <code>--></code>. All occurrences of the <code>#</code> character can be removed. <p> Secondly, the use of <code><</code> and <code>></code> characters would upset the structure of the XML build file. Environment variables are now enclosed by an opening <code>${</code> and a closing <code>}</code>. This syntax also allows you to use Ant properties within the ProGuard configuration. Other occurrences of <code><</code> and <code>></code> have to be encoded as <code>&lt;</code> and <code>&gt;</code>. <p> <h3>3. XML configuration tags</h3> If you really prefer a full-blown XML configuration, you can replace the ProGuard configuration options by XML configuration tags. The resulting configuration will be equivalent, but much more verbose and difficult to read, as XML goes. The remainder of this page presents the supported tags. For a more extensive discussion of their meaning, please consult the traditional <a href="usage.html">Usage</a> section. You can find some sample configuration files in the <code>examples/ant</code> directory of the ProGuard distribution. <p> <a name="proguard"> </a> <h2>Task Attributes and Nested Elements</h2> The <code><b><proguard></b></code> task and the <code><b><proguardconfiguration></b></code> task can have the following attributes (only for <code><proguard></code>) and nested elements: <dl> <dt><a name="configuration_attribute"><code><b>configuration</b></code></a> = "<i>filename</i>"</dt> <dd>Read and merge options from the given ProGuard-style configuration file. Note: for reading XML-style configurations, use the <a href="#configuration_element"><code>configuration</code></a> <i>element</i>.</dd> <dt><a href="usage.html#dontskipnonpubliclibraryclasses"><code><b>skipnonpubliclibraryclasses</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Ignore non-public library classes.</dd> <dt><a href="usage.html#dontskipnonpubliclibraryclassmembers"><code><b>skipnonpubliclibraryclassmembers</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Ignore package visible library class members.</dd> <dt><a href="usage.html#target"><code><b>target</b></code></a> = "<i>version</i>" (default = none)</dt> <dd>Set the given version number in the processed classes.</dd> <dt><a href="usage.html#forceprocessing"><code><b>forceprocessing</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Process the input, even if the output seems up to date.</dd> <dt><a href="usage.html#printseeds"><code><b>printseeds</b></code></a> = "<i>boolean or filename</i>" (default = false)</dt> <dd>List classes and class members matched by the various <code>keep</code> commands, to the standard output or to the given file.</dd> <dt><a href="usage.html#dontshrink"><code><b>shrink</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Shrink the input class files.</dd> <dt><a href="usage.html#printusage"><code><b>printusage</b></code></a> = "<i>boolean or filename</i>" (default = false)</dt> <dd>List dead code of the input class files, to the standard output or to the given file.</dd> <dt><a href="usage.html#dontoptimize"><code><b>optimize</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Optimize the input class files.</dd> <dt><a href="usage.html#optimizationpasses"><code><b>optimizationpasses</b></code></a> = "<i>n</i>" (default = 1)</dt> <dd>The number of optimization passes to be performed.</dd> <dt><a href="usage.html#allowaccessmodification"><code><b>allowaccessmodification</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Allow the access modifiers of classes and class members to be modified, while optimizing.</dd> <dt><a href="usage.html#mergeinterfacesaggressively"><code><b>mergeinterfacesaggressively</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Allow any interfaces to be merged, while optimizing.</dd> <dt><a href="usage.html#dontobfuscate"><code><b>obfuscate</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Obfuscate the input class files.</dd> <dt><a href="usage.html#printmapping"><code><b>printmapping</b></code></a> = "<i>boolean or filename</i>" (default = false)</dt> <dd>Print the mapping from old names to new names for classes and class members that have been renamed, to the standard output or to the given file.</dd> <dt><a href="usage.html#applymapping"><code><b>applymapping</b></code></a> = "<i>filename</i>" (default = none)</dt> <dd>Reuse the given mapping, for incremental obfuscation.</dd> <dt><a href="usage.html#obfuscationdictionary"><code><b>obfuscationdictionary</b></code></a> = "<i>filename</i>" (default = none)</dt> <dd>Use the words in the given text file as obfuscated field names and method names.</dd> <dt><a href="usage.html#classobfuscationdictionary"><code><b>classobfuscationdictionary</b></code></a> = "<i>filename</i>" (default = none)</dt> <dd>Use the words in the given text file as obfuscated class names.</dd> <dt><a href="usage.html#packageobfuscationdictionary"><code><b>packageobfuscationdictionary</b></code></a> = "<i>filename</i>" (default = none)</dt> <dd>Use the words in the given text file as obfuscated package names.</dd> <dt><a href="usage.html#overloadaggressively"><code><b>overloadaggressively</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Apply aggressive overloading while obfuscating.</dd> <dt><a href="usage.html#useuniqueclassmembernames"><code><b>useuniqueclassmembernames</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Ensure uniform obfuscated class member names for subsequent incremental obfuscation.</dd> <dt><a href="usage.html#dontusemixedcaseclassnames"><code><b>usemixedcaseclassnames</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Generate mixed-case class names while obfuscating.</dd> <dt><a href="usage.html#flattenpackagehierarchy"><code><b>flattenpackagehierarchy</b></code></a> = "<i>package_name</i>" (default = none)</dt> <dd>Repackage all packages that are renamed into the single given parent package.</dd> <dt><a href="usage.html#repackageclasses"><code><b>repackageclasses</b></code></a> = "<i>package_name</i>" (default = none)</dt> <dd>Repackage all class files that are renamed into the single given package.</dd> <dt><a href="usage.html#renamesourcefileattribute"><code><b>renamesourcefileattribute</b></code></a> = "<i>string</i>" (default = none)</dt> <dd>Put the given constant string in the <code>SourceFile</code> attributes.</dd> <dt><a href="usage.html#dontpreverify"><code><b>preverify</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Preverify the processed class files if they are targeted at Java Micro Edition or at Java 6 or higher.</dd> <dt><a href="usage.html#microedition"><code><b>microedition</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Targets the processed class files at Java Micro Edition.</dd> <dt><a href="usage.html#verbose"><code><b>verbose</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Write out some more information during processing.</dd> <dt><a href="usage.html#dontnote"><code><b>note</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Print notes about potential mistakes or omissions in the configuration. Use the nested element <a href="#dontnote">dontnote</a> for more fine-grained control.</dd> <dt><a href="usage.html#dontwarn"><code><b>warn</b></code></a> = "<i>boolean</i>" (default = true)</dt> <dd>Print warnings about unresolved references. Use the nested element <a href="#dontwarn">dontwarn</a> for more fine-grained control. <i>Only use this option if you know what you're doing!</i></dd> <dt><a href="usage.html#ignorewarnings"><code><b>ignorewarnings</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Print warnings about unresolved references, but continue processing anyhow. <i>Only use this option if you know what you're doing!</i></dd> <dt><a href="usage.html#printconfiguration"><code><b>printconfiguration</b></code></a> = "<i>boolean or filename</i>" (default = false)</dt> <dd>Write out the entire configuration in traditional ProGuard style, to the standard output or to the given file. Useful to replace unreadable XML configurations.</dd> <dt><a href="usage.html#dump"><code><b>dump</b></code></a> = "<i>boolean or filename</i>" (default = false)</dt> <dd>Write out the internal structure of the processed class files, to the standard output or to the given file.</dd> <dt><a href="usage.html#injars"><code><b><injar</b></code></a> <a href="#classpath"><i>class_path</i></a> <code><b>/></b></code></dt> <dd>Specifies the program jars (or wars, ears, zips, or directories).</dd> <dt><a href="usage.html#outjars"><code><b><outjar</b></code></a> <a href="#classpath"><i>class_path</i></a> <code><b>/></b></code></dt> <dd>Specifies the name of the output jars (or wars, ears, zips, or directories).</dd> <dt><a href="usage.html#libraryjars"><code><b><libraryjar</b></code></a> <a href="#classpath"><i>class_path</i></a> <code><b>/></b></code></dt> <dd>Specifies the library jars (or wars, ears, zips, or directories).</dd> <dt><a href="usage.html#keepdirectories"><code><b><keepdirectory name = </b></code></a>"<i>directory_name</i>" <code><b>/></b></code><br/> <a href="usage.html#keepdirectories"><code><b><keepdirectories filter = </b></code></a>"<a href="usage.html#filefilters"><i>directory_filter</i></a>" <code><b>/></b></code></dt> <dd>Keep the specified directories in the output jars (or wars, ears, zips, or directories).</dd> <dt><a href="usage.html#keep"><code><b><keep</b></code></a> <a href="#keepmodifier"><i>modifiers</i></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></keep></b></code></dt> <dd>Preserve the specified classes <i>and</i> class members.</dd> <dt><a href="usage.html#keepclassmembers"><code><b><keepclassmembers</b></code></a> <a href="#keepmodifier"><i>modifiers</i></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></keepclassmembers></b></code></dt> <dd>Preserve the specified class members, if their classes are preserved as well.</dd> <dt><a href="usage.html#keepclasseswithmembers"><code><b><keepclasseswithmembers</b></code></a> <a href="#keepmodifier"><i>modifiers</i></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></keepclasseswithmembers></b></code></dt> <dd>Preserve the specified classes <i>and</i> class members, if all of the specified class members are present.</dd> <dt><a href="usage.html#keepnames"><code><b><keepnames</b></code></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></keepnames></b></code></dt> <dd>Preserve the names of the specified classes <i>and</i> class members (if they aren't removed in the shrinking step).</dd> <dt><a href="usage.html#keepclassmembernames"><code><b><keepclassmembernames</b></code></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></keepclassmembernames></b></code></dt> <dd>Preserve the names of the specified class members (if they aren't removed in the shrinking step).</dd> <dt><a href="usage.html#keepclasseswithmembernames"><code><b><keepclasseswithmembernames</b></code></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></keepclasseswithmembernames></b></code></dt> <dd>Preserve the names of the specified classes <i>and</i> class members, if all of the specified class members are present (after the shrinking step).</dd> <dt><a href="usage.html#whyareyoukeeping"><code><b><whyareyoukeeping</b></code></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></whyareyoukeeping></b></code></dt> <dd>Print details on why the given classes and class members are being kept in the shrinking step.</dd> <dt><a href="usage.html#assumenosideeffects"><code><b><assumenosideeffects</b></code></a> <a href="#classspecification"><i>class_specification</i></a> <code><b>></b></code> <a href="#classmemberspecification"><i>class_member_specifications</i></a> <code><b></assumenosideeffects></b></code></dt> <dd>Assume that the specified methods don't have any side effects, while optimizing. <i>Only use this option if you know what you're doing!</i></dd> <dt><a href="usage.html#optimizations"><code><b><optimization name = </b></code></a>"<a href="optimizations.html"><i>optimization_name</i></a>" <code><b>/></b></code><br/> <a href="usage.html#optimizations"><code><b><optimizations filter = </b></code></a>""<a href="optimizations.html"><i>optimization_filter</i></a>" <code><b>/></b></code></dt> <dd>Perform only the specified optimizations.</dd> <dt><a href="usage.html#keeppackagenames"><code><b><keeppackagename name = </b></code></a>"<i>package_name</i>" <code><b>/></b></code><br/> <a href="usage.html#keeppackagenames"><code><b><keeppackagenames filter = </b></code></a>"<a href="usage.html#filters"><i>package_filter</i></a>" <code><b>/></b></code></dt> <dd>Keep the specified package names from being obfuscated. If no name is given, all package names are preserved.</dd> <dt><a href="usage.html#keepattributes"><code><b><keepattribute name = </b></code></a>"<i>attribute_name</i>" <code><b>/></b></code><br/> <a href="usage.html#keepattributes"><code><b><keepattributes filter = </b></code></a>"<a href="usage.html#filters"><i>attribute_filter</i></a>" <code><b>/></b></code></dt> <dd>Preserve the specified optional Java bytecode attributes, with optional wildcards. If no name is given, all attributes are preserved.</dd> <dt><a href="usage.html#adaptclassstrings"><code><b><adaptclassstrings filter = </b></code></a>"<a href="usage.html#filters"><i>class_filter</i></a>" <code><b>/></b></code></dt> <dd>Adapt string constants in the specified classes, based on the obfuscated names of any corresponding classes.</dd> <dt><a href="usage.html#adaptresourcefilenames"><code><b><adaptresourcefilenames filter = </b></code></a>"<a href="usage.html#filefilters"><i>file_filter</i></a>" <code><b>/></b></code></dt> <dd>Rename the specified resource files, based on the obfuscated names of the corresponding class files.</dd> <dt><a href="usage.html#adaptresourcefilecontents"><code><b><adaptresourcefilecontents filter = </b></code></a>"<a href="usage.html#filefilters"><i>file_filter</i></a>" <code><b>/></b></code></dt> <dd>Update the contents of the specified resource files, based on the obfuscated names of the processed classes.</dd> <dt><a name="dontnote" /> <a href="usage.html#dontnote"><code><b><dontnote filter = </b></code></a>"<a href="usage.html#filters"><i>class_filter</i></a>" <code><b>/></b></code></dt> <dd>Don't print notes about classes matching the specified class name filter.</dd> <dt><a name="dontwarn" /> <a href="usage.html#dontwarn"><code><b><dontwarn filter = </b></code></a>"<a href="usage.html#filters"><i>class_filter</i></a>" <code><b>/></b></code></dt> <dd>Don't print warnings about classes matching the specified class name filter. <i>Only use this option if you know what you're doing!</i></dd> <dt><a name="configuration_element"><code><b><configuration refid = </b></code></a>"<i>ref_id</i>" <code><b>/></b></code></dt> <dd>Includes the configuration specified in the <code><proguardconfiguration></code> task (or <code><proguard></code> task) with the attribute <code>id</code> = "<i>ref_id</i>". Note that only the nested elements of this configuration are considered, not the attributes. Also note: for reading ProGuard-style configuration files, use the <a href="#configuration_attribute"><code>configuration</code></a> <i>attribute</i>.</dd> </dl> <a name="classpath"> </a> <h2>Class Path Attributes and Nested Elements</h2> The jar tags are path tags, so they can have any of the path attributes (or nested elements). The most common attributes are: <dl> <dt><code><b>path</b></code> = "<i>path</i>"</dt> <dd>The names of the jars (or wars, ears, zips, or directories), separated by the path separator.</dd> <dt><code><b>location</b></code> = "<i>name</i>" (or <code><b>file</b></code> = "<i>name</i>", or <code><b>dir</b></code> = "<i>name</i>", or <code><b>name</b></code> = "<i>name</i>")</dt> <dd>Alternatively, the name of a single jar (or war, ear, zip, or directory).</dd> <dt><code><b>refid</b></code> = "<i>ref_id</i>"</dt> <dd>Alternatively, a reference to the path or file set with the attribute <code>id</code> = "<i>ref_id</i>".</dd> </dl> In addition, the jar tags can have ProGuard-style filter attributes: <dl> <dt><code><b>filter</b></code> = "<a href="usage.html#filefilters"><i>file_filter</i></a>"</dt> <dd>An optional filter for all class file names and resource file names that are encountered.</dd> <dt><code><b>jarfilter</b></code> = "<a href="usage.html#filefilters"><i>file_filter</i></a>"</dt> <dd>An optional filter for all jar names that are encountered.</dd> <dt><code><b>warfilter</b></code> = "<a href="usage.html#filefilters"><i>file_filter</i></a>"</dt> <dd>An optional filter for all war names that are encountered.</dd> <dt><code><b>earfilter</b></code> = "<a href="usage.html#filefilters"><i>file_filter</i></a>"</dt> <dd>An optional filter for all ear names that are encountered.</dd> <dt><code><b>zipfilter</b></code> = "<a href="usage.html#filefilters"><i>file_filter</i></a>"</dt> <dd>An optional filter for all zip names that are encountered.</dd> </dl> <a name="keepmodifier"> </a> <h2>Keep Modifier Attributes</h2> The keep tags can have the following <i>modifier</i> attributes: <dl> <dt><a href="usage.html#allowshrinking"><code><b>allowshrinking</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Specifies whether the entry points specified in the keep tag may be shrunk.</dd> <dt><a href="usage.html#allowoptimization"><code><b>allowoptimization</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Specifies whether the entry points specified in the keep tag may be optimized.</dd> <dt><a href="usage.html#allowobfuscation"><code><b>allowobfuscation</b></code></a> = "<i>boolean</i>" (default = false)</dt> <dd>Specifies whether the entry points specified in the keep tag may be obfuscated.</dd> </dl> <a name="classspecification"> </a> <h2>Class Specification Attributes and Nested Elements</h2> The keep tags can have the following <i>class_specification</i> attributes and <i>class_member_specifications</i> nested elements: <dl> <dt><code><b>access</b></code> = "<i>access_modifiers</i>"</dt> <dd>The optional access modifiers of the class. Any space-separated list of "public", "final", and "abstract", with optional negators "!".</dd> <dt><code><b>type</b></code> = "<i>type</i>"</dt> <dd>The optional type of the class: one of "class", "interface", or "!interface".</dd> <dt><code><b>name</b></code> = "<i>class_name</i>"</dt> <dd>The optional fully qualified name of the class, with optional wildcards.</dd> <dt><code><b>extends</b></code> = "<i>class_name</i>"</dt> <dd>The optional fully qualified name of the class the specified classes must extend, with optional wildcards.</dd> <dt><code><b>implements</b></code> = "<i>class_name</i>"</dt> <dd>The optional fully qualified name of the class the specified classes must implement, with optional wildcards.</dd> <dt><code><b><field</b></code> <a href="#classmemberspecification"><i>class_member_specification</i></a> <code><b>/></b></code></dt> <dd>Specifies a field.</dd> <dt><code><b><method</b></code> <a href="#classmemberspecification"><i>class_member_specification</i></a> <code><b>/></b></code></dt> <dd>Specifies a method.</dd> <dt><code><b><constructor</b></code> <a href="#classmemberspecification"><i>class_member_specification</i></a> <code><b>/></b></code></dt> <dd>Specifies a constructor.</dd> </dl> <a name="classmemberspecification"> </a> <h2>Class Member Specification Attributes</h2> The class member tags can have the following <i>class_member_specification</i> attributes: <dl> <dt><code><b>access</b></code> = "<i>access_modifiers</i>"</dt> <dd>The optional access modifiers of the class. Any space-separated list of "public", "protected", "private", "static", etc., with optional negators "!".</dd> <dt><code><b>type</b></code> = "<i>type</i>"</dt> <dd>The optional fully qualified type of the class member, with optional wildcards. Not applicable for constructors, but required for methods for which the <code>parameters</code> attribute is specified.</dd> <dt><code><b>name</b></code> = "<i>name</i>"</dt> <dd>The optional name of the class member, with optional wildcards. Not applicable for constructors.</dd> <dt><code><b>parameters</b></code> = "<i>parameters</i>"</dt> <dd>The optional comma-separated list of fully qualified method parameters, with optional wildcards. Not applicable for fields, but required for constructors, and for methods for which the <code>type</code> attribute is specified.</dd> </dl> <hr> <address> Copyright © 2002-2009 <a href="http://www.graphics.cornell.edu/~eric/">Eric Lafortune</a>. </address> </body> </html>