The purpose of this chapter is to show a migration path from an existing build in Ant to Maven.
The Maven migration example is based on the Spring Framework build, which uses an Ant script. This example will take you through the step-by-step process of migrating Spring to a modularized, component-based, Maven build.
You will learn how to start building with Maven, while still running your existing, Ant-based build system. This will allow you to evaluate Maven’s technology, while enabling you to continue with your required work.
You will learn how to use an existing directory structure (though you will not be following the standard, recommended Maven directory structure), how to split your sources into modules or components, how to run Ant tasks from within Maven, and among other things, you will be introduced to the concept of dependencies.
Introducing the Spring Framework
The Spring Framework is one of today’s most popular Java frameworks. For the purpose of this example, we will focus only on building version 2.0-m1 of Spring, which is the latest version at the time of writing.
The Spring release is composed of several modules, listed in build order:
Figure 1-1: Dependency relationship between Spring modules
In figure 1-1. you can see graphically the dependencies between the modules. Optional dependencies are indicated by dotted lines.
Each of these modules corresponds, more or less, with the Java package structure, and each produces a JAR. These modules are built with an Ant script from the following source directories:
test: contain JDK 1.4 compatible source code and JUnit tests respectively
tiger/test: contain additional JDK 1.5 compatible source code and
mock: contains the source code for the spring-mock module
aspectj/test: contain the source code for the spring-aspects module
Each of the source directories also include classpath resources (XML files, properties files, TLD files, etc.).
For Spring, the Ant script compiles each of these different source directories and then creates a JAR for each module, using inclusions and exclusions that are based on the Java packages of each class. The src and tiger/src directories are compiled to the same destination as the test and tiger/test directories, resulting in JARs that contain both 1.4 and 1.5 classes.