如何在 ant 中取消设置属性?所以它作为一个属性被完全删除了吗?
<condition property="proguard.config" value="proguard.cfg">
<isset property="proguarded"/>
</condition>
<condition property="proguard.config" value="">
<not>
<isset property="proguarded"/>
</not>
</condition>
这似乎可行。然而,即使存在诸如 proguard.config 之类的属性,proguard 也会运行。那么如何有条件地完全删除 proguard.config 作为属性呢?我知道如果 proguard 发现 .properties 文件中有一个 proguard.config 属性,它就会运行。
最佳答案
Properties are immutable: whoever sets a property first freezes it for the rest of the build; they are most definitely not variables.
话虽这么说,但有几个解决方法:
Local Task - 给定范围内的本地属性“遮蔽”更高范围内的同名属性(在 Macrodefs 中特别有用)
Ant-Contrib Variable Task - Ant-Contrib 提供了灵 active ,但它也增加了依赖性,有时会诱使您编写程序 Ant 代码,这些代码可能更好地用 Ant 脚本或自定义 Ant 任务表达
在上面的示例中,如果属性 proguarded
在执行 Ant 项目期间没有更改,则无需取消设置该属性。例如,您可以按如下方式有条件地执行目标:
<target name="proguarded-target" if="proguarded">
...
</target>
<target name="not-proguarded-target" unless="proguarded">
...
</target>
关于java - 使用条件在 Ant 中取消设置属性和在 Ant 中删除属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10644499/