Hierarchy and distribution of tasks among Ant build files in Java EE application from the JUnit unit tests perspective

旧巷老猫 提交于 2019-12-24 17:23:27

问题


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?


回答1:


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

  • ivy simple shared repository


来源:https://stackoverflow.com/questions/14258851/hierarchy-and-distribution-of-tasks-among-ant-build-files-in-java-ee-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!