【问题标题】:Modify global variable Ant修改全局变量 Ant
【发布时间】:2012-02-09 13:46:30
【问题描述】:

我想在一个目标中更改 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'

【问题讨论】:

标签: ant ant-contrib


【解决方案1】:

两者都可以使用:

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

正如 Oers 在他对您的问题的评论中已经提到的那样,或者使用更直接的方法来处理 let taskAnt addon Flaka

<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>

【讨论】:

  • 未设置的变量不会影响目标之外的变量。这意味着如果我添加此更改,“print-me”目标中的打印仍会打印“hello”......我会尝试这个附加组件并让你知道。谢谢!
【解决方案2】:

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

【讨论】:

  • 你可能想举个例子来说明你的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多