Ant:如何防止属性被传递给它的后代调用?
Ant: How to prevent the properties from being passed down to its descendant calls?
build.xml
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true">
<property name="messages" value="NOT_FOO_BAR"/>
</ant>
</target>
构建-foo.xml
<target name="foo">
<property name="messages" value="FOO"/>
<ant antfile="build-bar.xml" dir="${basedir}" target="bar"
inheritAll="false" useNativeBasedir="true">
</ant>
</target>
构建-bar.xml
<target name="bar">
<property name="messages" value="BAR"/>
<echo message="messages = ${messages}"/>
</target>
尝试过:
ant -buildfile build-foo.xml foo
the messages is BAR, as expected.
ant -buildfile build.xml main
the messages is NOT_FOO_BAR.
main 中的属性被向下传递多级,即使在构建中不需要它-foo.xml:inheritAll=false。
如何防止属性被传递给它的后代调用?谢谢
来自 ant manual ant task :
You can also set properties in the new project from the old project by
using nested property tags. These properties are always passed to
the new project and any project created in that project regardless
of the setting of inheritAll. This allows you to parameterize your
subprojects.
代替:
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true"/>
<property name="messages" value="NOT_FOO_BAR"/>
</target>
符合您的期望。
build.xml
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true">
<property name="messages" value="NOT_FOO_BAR"/>
</ant>
</target>
构建-foo.xml
<target name="foo">
<property name="messages" value="FOO"/>
<ant antfile="build-bar.xml" dir="${basedir}" target="bar"
inheritAll="false" useNativeBasedir="true">
</ant>
</target>
构建-bar.xml
<target name="bar">
<property name="messages" value="BAR"/>
<echo message="messages = ${messages}"/>
</target>
尝试过:
ant -buildfile build-foo.xml foo
the messages is BAR, as expected.
ant -buildfile build.xml main
the messages is NOT_FOO_BAR.
main 中的属性被向下传递多级,即使在构建中不需要它-foo.xml:inheritAll=false。
如何防止属性被传递给它的后代调用?谢谢
来自 ant manual ant task :
You can also set properties in the new project from the old project by using nested property tags. These properties are always passed to the new project and any project created in that project regardless of the setting of inheritAll. This allows you to parameterize your subprojects.
代替:
<target name="main">
<ant antfile="build-foo.xml" dir="${basedir}" target="foo"
inheritAll="false" useNativeBasedir="true"/>
<property name="messages" value="NOT_FOO_BAR"/>
</target>
符合您的期望。