简体   繁体   中英

Java Ant - how to pass a ProGuard task arguments and use them inside a configuration file?

I have this in my build.xml:

<target depends="build-jar" name="proguard">
    <taskdef resource="proguard/ant/task.properties" classpath="tools/proguard4.6/lib/proguard.jar" />
    <proguard configuration="ant/proguard.conf" />
</target>

It works fine.

Inside the configuration file (ie "ant/proguard.conf") I'm trying to access properties defined in this build.xml file but I'm always getting this kind of error:

Value of system property 'jar.final_name' is undefined in '<jar.final_name>' in line 1 of file '.......\ant\proguard.conf'

The error is clear. Question is how I do what I'm trying to?
If I'd do it the "Embedded ProGuard configuration options" way I could use these properties like any other property in build.xml, but I'm trying to keep the files separate.

How do I do that then?

By default, Ant doesn't provide a way to set java system properties for its tasks. You can only specify -D options in the ANT_OPTS system variable when starting Ant itself.

I'll consider supporting the use of Ant properties in referenced ProGuard configurations (being the developer of ProGuard).

For the time being, an acceptable solution might be to specify input and output jars in Ant's XML-style:

<proguard configuration="ant/proguard.conf">
  <injar      name="${injar}" />
  <outjar     name="${outjar}" />
  <libraryjar name="${java.home}/lib/rt.jar" />
</proguard>

This part of the configuration is more closely tied to the Ant script anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM