1

我想在一个目标中更改 Ant 文件中的“变量”,并在另一个目标中查看该更改。

<variable name="foo" value="hello" />
<target name="print-me">
    <echo message="${foo}" />
    <antcall target="change-me" />
    <echo message="${foo}" />
</target>

<target name="change-me">
    <variable name="foo" value="world" />
</target>

虽然我希望它打印: 'hello , world' ,但它会打印 'hello, hello'

4

2 回答 2

2

要么使用:

<target name="change-me">
    <variable name="foo" unset="true"/>
    <variable name="foo" value="world"/>
</target>

正如 Oers 在他对您的问题的评论中已经提到的那样,或者对Ant 插件 Flaka使用更
直接的方法:let task

<project xmlns:fl="antlib:it.haefelinger.flaka">

...
<!-- overwrite any existing property or userproperty
     (those properties defined on the commandline via -Dfoo=bar ..) --> 
<fl:let> foo ::= 'world'</fl:let>

...
</project>
于 2012-02-09T22:22:08.860 回答
-1

如果您使用 ant-contrib 标签,这将起作用。

于 2013-01-18T22:51:32.193 回答