Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant build scripts, antcall, dependencies, etc

I have a build script and as part of that script it copies a jar file to a directory, for ease lets call it the utils jar. the utils jar is built by another build script sitting in another directory. What im trying to do have my build script run the utils build script so that I can ensure the utils jar is up to date.

So I know I need to import the utils build file.

<import file="../utils/build/build.xml" /> 

Which doesn't work because the import task, unlike almost every other ant taks, doesn't run from basedir, it runs from the pwd. So to get around that I have this little ditty, which does successfully import the build file

  <property name="baseDirUpOne" location=".." />   <import file="${baseDirUpOne}/utils/build/build.xml" /> 

So now that ive solved my import problem I need to call the task, well that should be easy right:

<antcall target="utils.package" /> 

note that in the above, utils is the project name of ../utils/build/build.xml

the problem I'm now running into is that ant call doesn't execute in ../utils/build so what I need, and cant find, is a runat property or something similar, essentially:

<antcall target="utils.package" runat="../utils/build" /> 

The reason I need this is that in my utils build file the step to select which code to copy to the jar is based on relative paths so as to avoid hardcoding paths in my ant file. Any ideas?

like image 588
shsteimer Avatar asked Aug 12 '08 13:08

shsteimer


People also ask

What is an Ant build script?

Ant is a Java-based build tool created as part of the Apache open-source project. You can think of it as a Java version of make. Ant scripts have a structure and are written in XML. Similar to make, Ant targets can depend on other targets.

What is Antcall target?

When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.

How do I build an Ant build xml?

Create Ant build file In the Project tool window, select the directory, where the build file should be created. Right-click the directory and from the context menu, select New | File ( Alt+Insert ). In the New File dialog, specify the name of the new file with the xml extension, for example, build. xml.

How does Ant build system work?

Ant builds are based on three blocks: tasks, targets and extension points. A task is a unit of work which should be performed and constitutes of small atomic steps, for example compile source code or create Javadoc. Tasks can be grouped into targets. A target can be directly invoked via Ant.


2 Answers

I've got something similar set up: I have a main Ant build.xml which calls a separate build.xml that takes care of building my tests. This is how I do it:

<target name="build-tests">     <subant target="build">       <fileset dir="${test.home}" includes="build.xml"/>     </subant> </target> 

The trick is to use subant instead of antcall. You don't have to import the other build file.

like image 153
Theo Avatar answered Oct 25 '22 15:10

Theo


Try using the "ant" task instead of the "antcall" task, which runs the imported build directly instead of importing it into the current build file. It has a "dir" parameter:

the directory to use as a basedir for the new Ant project. Defaults to the current project's basedir, unless inheritall has been set to false, in which case it doesn't have a default value. This will override the basedir setting of the called project.

So you could do:

<ant antfile="${baseDirUpOne}/utils/build/build.xml" dir="../utils/build" /> 

or something like that.

like image 29
James Sulak Avatar answered Oct 25 '22 17:10

James Sulak