【问题标题】:Working of ant's property - tricky & alternate way to handle蚂蚁财产的工作 - 处理的棘手和替代方式
【发布时间】:2013-11-19 06:44:26
【问题描述】:

使用简单的 ant 属性很棘手,并且不允许轻松设置所需的值(属性是不可变的)。使用 ant-conrib 的 var 任务可以设置和取消设置属性。

将 ant 属性设计为以如此复杂的方式工作的背后有什么真正的或充分的理由吗?

<property name="some.ant.prop" value=""/>

        <if>
            <isset property="some.ant.prop"/>
            <then>
                <echo message="immutable ant prop - not good, defined and just even set to null string : ${some.ant.prop}"/>

                <property name="some.ant.prop" value="no-effect-value"/>
                <echo message="no-effect on changing already defined prop : ${some.ant.prop}"/>

                <var name="some.ant.prop" unset="true"/>
                <property name="some.ant.prop" value="any-value-accepted"/>
                <echo message="Overwritten prop value: ${some.ant.prop}"/>

            </then>
        </if>

不是为了讨论或争论,但很高兴知道更可行的替代方案。谢谢。

【问题讨论】:

    标签: ant properties ant-contrib


    【解决方案1】:

    Ant 不是编程语言!
    一旦设置属性在 ant 设计中是不可变的。
    经常讨论(太多)优点和缺点,我不会详细说明。

    克服这些限制的几种可能性:
    在过去,人们使用 antcall 来达到这个目的——尽管有它的所有缺点,请搜索“antcall vs. macrodef”以获取详细信息。 Ant 1.6 引入了macrodef,Ant 1.8 带来了一个新的local 任务。
    如果 macrodef 和 local 不够,您可以使用带有内置 javascript 引擎(自 JDK 1.6 起)或 Groovy 的脚本任务来访问 ant api。

    还有像 f.e. 这样的 Ant 插件。 antcontrib 或Flaka。如果你觉得 antcontrib var / unset 太笨拙, Flaka 的 let 任务提供了一种更直接的方法来覆盖属性:

    <!-- set a new property -->
    <fl:let>foo := 'bar'</fl:let>
    
    <!-- overwrite an existing property or userproperty
         (those properties defined on the commandline via -Dfoo=bar ..)
         notice the double '::' in foo ::= 'baz' -->
    <fl:let>foo ::= 'baz'</fl:let>
    

    最后:
    要么习惯 ant 及其局限性(但不要使用 antcall !)或
    使用 Ant 插件
    use ant from groovy
    或切换到Gradle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 1970-01-01
      相关资源
      最近更新 更多