Calling depends targets from parent build.xml inside includes xml

余生长醉 提交于 2019-12-19 11:24:17

问题


Is it possible for xml files that are part of 'includes' inside build.xml to have depends on targets from that build.xml (backwards dependency)? Or do I need to create a chain of only forward dependencies, and having "depends" on includedFile.target down? If this is possible, how do I call these parent targets?

I am trying to extract several targets outside of a very long build.xml file, in a situation like this:

build.xml defines a very common target, buildMe used throughout the build.xml file. It also defines a target runTasks. It includes someTasks.xml. runTasks depends on buildMe and someTasks.groupOfTasks.

someTasks.xml define targets groupOfTasks, task0, task1, task2. groupOfTasks depends on task0, task1 and task2. Now can task0 task1 or task2 depend on buildMe from build.xml, or some other target defined in build.xml?


回答1:


This works for me: In the main project file the target default depends on a target from commontasks.xml which depends on a target from the main project file:

<project name="main" default="default">

  <import file="commontasks.xml" as="common" />

  <target name="default" depends="common.hello" description="the main project">
  </target>

  <target name="initMain">
    <echo>initializing main</echo>
    <property name="aValue" value="MAIN" />
  </target>

<project name="commontasks" >

  <target name="hello" depends="initMain">
    <echo>hello from common tasks</echo>
    <echo>aValue: ${aValue}</echo>
  </target>

When I run the ant build, I get:

initMain:
 [echo] initializing main
common.hello:
 [echo] hello from common tasks
 [echo] aValue: MAIN
default:
BUILD SUCCESSFUL

The dependency is target default depends on hello depends on initMain and hello can use properties defined in initMain.



来源:https://stackoverflow.com/questions/25198800/calling-depends-targets-from-parent-build-xml-inside-includes-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!