Create an ant file to run other ant files

2019-03-15 08:07发布

问题:

I saw this relevant question but my situation is different so asking this again. Basically, I have 12 ant files that I have to run in a specific sequence. For each ant file, I select a different target, such as "create" or "build and deploy all." How can I create an ant file that will call of the right targets for all of these files?

Pseudocode:

<Call antFile1, "clean">
<Call antFile1, "create">
<Call antFile2, "build">
        .
        .
        .
<Call antfile12, "build and deploy all">

回答1:

Maybe have a target like below in encompassing ant file:

<target name="all">
     <ant antfile="antFile1" target="clean" />
     <ant antfile="antFile2" target="create" />
     ...
</target>

Refer here: http://ant.apache.org/manual/Tasks/ant.html



回答2:

You can also have import tags:

<import file="my_ant_file.xml">

And then you can call the ant targets in that file. You may want to qualify (add a prefix to) your target names to avoid ambiguity if you do that.

EDIT: Calling the ant targets from the imported file is exactly the same as calling local targets:

<antcall target="my_local_target">
<antcall target="my_target_from_an_imported_file">

You can also use them as dependencies:

<target name="my_target" depends="my_target_from_an_imported_file">

Think of it the same way as importing in any programming language. Once it's imported you can use it as-if it were just another target in your file.

Here is the import documentation.



标签: ant