开发者

Set a property inside one ant target and use it in another target

开发者 https://www.devze.com 2023-02-01 03:09 出处:网络
My build file is <target name=\"default\"> <antcall target=\"child_target\"/> <echo> ${prop1}</echo>

My build file is

<target name="default">  
 <antcall target="child_target"/>  
 <echo> ${prop1}   </echo>  
</target>

<target name="child_target">  
 <property name="prop1" value="val1"/>   
</target>

I get an error that ${prop1} has not been set. How do I set a开发者_运维技巧 property in the target?


antcall creates a new project. From the Ant documentation:

The called target(s) are run in a new project; be aware that this means properties, references, etc. set by called targets will not persist back to the calling project.

Use depends instead:

<project default="default">
  <target name="default" depends="child_target">
    <echo>${prop1}</echo>
  </target>
  <target name="child_target">
    <property name="prop1" value="val1"/>
  </target>
</project>


Old and probably dead issue I know, but a property file loaded outside targets but inside the project would also work. Android does this with local.properties like so:

<?xml version="1.0" encoding="UTF-8"?>
<project name="avia" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />
0

精彩评论

暂无评论...
验证码 换一张
取 消