Let me preface by saying that I am new to Ant. As in, I just started learning it 2 days ago in order to accomplish this task.
What I'm trying to do is create a "master" ant script that calls several other ant scripts. For example:
Project A
- contains build.xml, target "makeProjectAjar"
- output: A.jar
Project B
- contains build.xml, target "makeProjectBjar"
- output: B.jar
Project C
- contains build.xml, target "makeProjectCjar"
- output: C.jar
Project D
- contains build.xml, target "finalPackage"
- Must first build Project A, Project B, Project C
- Copy A.jar, B.jar, C.jar to Project D
- Package all of this into D.jar
Right now I have all of the individual builds for A, B, and C working. By this, I mean I can run 'ant' from any of these folders and it will build the project and produce a jar file. If I build A, B, and C this way, I have 3 jar files. I can then copy them into D and package it into the final jar. That works fine.
But what I'd like is to be able to trigger the A, B, and C builds from within build.xml of Project D. I've tried this:
<?xml version="1.0" encoding="UTF-8"?>
<project name="CommonJava" default="makeCommonJavaJar" basedir=".">
<import file="../Common/build.xml"/>
<import file="../CommonAndroid/build.xml"/>
<target name="makeCommonJavaJar" description="Create a jar for the CommonJava project"
depends="clean">
<mkdir dir="build" />
<jar jarfile="./build/commonjava.jar" includes="*.class" />
</target>
<target name="clean">
<delete dir="build" />
</target>
<target name="build+package" description="Build all prerequisites and package them">
<antcall target="makeCommonJar"/>
<antcall target="makeAndroidJar"/>
</target>
</project>
makeCommonJar is a target in Common/build.xml (Project A) and makeAndroidJar is a target in ../CommonAndroid/build.xml (Project B). However, it seems that when using <import>
, it runs from the context of the calling folder. Meaning resources referenced by Project B are unavailable since it's running from Project D. Does that make sense?
Long question short... using Ant, how can I call build.xml files in other projects in order to build those projects first?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…