Intermodule dependency in ant

2020-02-15 03:52发布

问题:

I am using Ant 1.8

I have multiple modules in intelliJ IDEA. Each module has a build.xml and currently i need to browse till build.xml of that file and run ant for every module. e.g. module B's build success depends on whether module A's build was successful.

Now, i want to update this process. It will be great if an option exists wherein i can write a single build process which will first build distribution for module A and then while building distribution for B, it will be checked if build for module A is successful.

Is there any way using current Ant mechanism. i could see something similar in ivy but i cant use it in my project.

Please suggest an approach using basic Ant features.

回答1:

The subant task in ANT is the most flexible way to invoke a multi-module build, for example:

<project name="parent" default="build">

    <target name="build">
        <subant>
            <filelist dir=".">
                <file name="moduleA/build.xml"/>
                <file name="moduleB/build.xml"/>
            </filelist>
            <target name="clean"/>
            <target name="build"/>
        </subant>
    </target>

</project>

Project structure

|-- build.xml
|-- moduleA
|   `-- build.xml
`-- moduleB
    `-- build.xml

Note:

In my opinion the most powerful way to use this task is to combine it with the buildlist task from Apache ivy. Let the ivy inter-module dependency declarations automatically determine the module build order.



回答2:

Thanks Mark!! Your answer helped me a lot.

In addition to above answer I would like to add details, if properties are being loaded from properties file.

Project Structure:


|-- build.xml
|-- ProjectOne
    -- build.xml
    -- antbuilds.properties
|-- ProjectTwo
    -- build.xml
    -- antbuilds.properties

Common ANT build file:

<project name="Parent" default="all">
<target name="ProjectOne">
    <subant>
        <property file="ProjectOne/antbuilds.properties"/>
        <filelist dir=".">
            <file name="ProjectOne/build.xml"/>
        </filelist>
        <target name="deploy"/>
    </subant>
</target>
<target name="ProjectTwo">
    <subant>
        <property file="ProjectTwo/antbuilds.properties"/>
        <filelist dir=".">
            <file name="ProjectTwo/build.xml"/>
        </filelist>
        <target name="deploy"/>
    </subant>
</target>
<target name="all" depends="ProjectOne, ProjectTwo">
</target>