我想写一个macrodef,它依赖于在另一个macrodef中设置的属性,例如这样,这不起作用...(macrodef不支持depends,除非属性)无论如何都要这样做?

<project name="mac">

    <property name="antlr.version" value="3.2"/>

    <macrodef name="check">
        <attribute name="dest"/>
        <attribute name="name"/>
        <attribute name="version"/>
        <sequential>
            <available file="@{dest}/@{name}-@{version}.jar" property="@{name}-exists"/>
        </sequential>
    </macrodef>

    <macrodef name="pull" depends="check" unless="@{name}-exists">
        <attribute name="url"/>
        <attribute name="dest"/>
        <attribute name="name"/>
        <attribute name="version"/>

        <sequential>
            <get src="@{url}" dest="@{dest}/@{name}-@{version}" verbose="true" ignoreerrors="true" unless="@{name}-exists"/>
        </sequential>
    </macrodef>

    <target name="pullall">
           <pull url="http://repo1.maven.org/maven2/org/antlr/antlr/${antlr.version}/antlr-${antlr.version}.jar" dest="." name="antlr" version="${antlr.version}"/>
    </target>

最佳答案

这似乎可行:

    <project name="mac">

        <property name="antlr.version" value="3.2"/>
        <property name="stringtemplate.version" value="4.0.2"/>

        <target name="check">
            <available file="${dest}/${name}-${version}.jar" property="jar-exists"/>
        </target>

        <target name="_pull" depends="check" unless="jar-exists">
            <get src="${url}" dest="${dest}/${name}-${version}.jar" verbose="true" ignoreerrors="true"/>
        </target>

        <macrodef name="pull">
            <attribute name="url"/>
            <attribute name="dest"/>
            <attribute name="name"/>
            <attribute name="version"/>

            <sequential>
                <antcall target="_pull">
                    <param name="url" value="@{url}"/>
                    <param name="dest" value="@{dest}"/>
                    <param name="name" value="@{name}"/>
                    <param name="version" value="@{version}"/>
                </antcall>
            </sequential>
        </macrodef>

        <target name="pullall">
        <pull url="http://repo1.maven.org/maven2/org/antlr/antlr/${antlr.version}/antlr-${antlr.version}.jar" dest="." name="antlr" version="${antlr.version}"/>
        <pull url="http://repo1.maven.org/maven2/org/antlr/stringtemplate/${stringtemplate.version}/stringtemplate-${stringtemplate.version}.jar" dest="." name="stringtemplate" version="${stringtemplate.version}"/>
        </target>

</project>

10-07 16:02