Hierarchy and distribution of tasks among Ant buil

2019-07-30 01:29发布

I have the following hierarchy in of the Ant build files in my application :

Application
|---MainProject
|       |__ build.xml
|
|---Project1
|       |__ build.xml
|
|---Project2
       |__ build.xml

The Ant targets, based on their tasks are distributed as follows:

1) MainProject build file gives ant calls to the clean target of all the other build files

2) The JUnit tests in all the projects are executed in the MainProject build file using a common junit target with junit tasks inside it.

3) All other tasks in the other build files are executed through ant calls to the build-project target in all other files.

4) The build-project target further decides the tasks to be carried out in individual files respectively.

How does this architecture look to you? What would be your approach for such a scenario? What is the recommended way to go about it?

标签: java ant junit
1条回答
聊天终结者
2楼-- · 2019-07-30 02:10

This would be a fairly typical multi-module build scenario in ANT which, over time, leads to fairly typical large monolithic project builds....

What I'd suggest is consider how Maven structures it's multi-module projects. You want to simulate Maven's concept of a "local repostory" a place where each module pushes its built artifacts. Never share classpaths, instead each "build.xml" file creates them based on files in the local repo:

<path id="compile.path">
    <fileset dir="${local.repo.containing.built.jars}" includes="*.jar"/>
    <fileset dir="${dir.containing.third.party.jars}" includes="*.jar"/>
</path>

The benefits

  • Each sub-module can be built in a stand-alone fashion (during development) without forcing a complete rebuild of the entire project.
  • Your 3rd party dependencies are clearly differientiated within your classpath

As your project grows you'll need to be conscious of interdependencies between modules. With a small number of submodules the build order is obvious, but as time passes, a sub-module may become dependent on lots of other sub-modules being built first.

Finally, the apache ivy project provides the tooling to add Maven-like features into your ANT build. There is a multi-module example, however, I found it difficult to understand as a beginner. I would put it onto your backlog and consider publishing sub-module artifacts into a Maven repository like Nexus in the future. This would make your ANT build compatible with other teams using alternative build technologies like Maven and Gradle.

Update

查看更多
登录 后发表回答