Each project will have a unique set of builds needs (e.g. Compilation, RMIC, idl compilation, aop compilation, retroweaving)

Determine if plugin exists for each need, request plugin if it does not

-

The pom file

The build instructions for a maven file are contained in file called pom.xml.

While poms can always define the same information, for our purposes we will make a distinction between two type of poms

Top level Pom

This is any pom whose defintions are inherited by another project (e.g. /jboss/build/pom.xml)

The top level pom can define build instructions which are picked up by child level builds. It is in this pom where you will define things such as

A list of modules to build

Common properties

Common build procedures (e.g. compiling manifests)

Version numbers of plugins and dependencies

A list of repositories to search for plugins and dependencies

<!-- Example top level pom -->
<project>
<!-- Build project description -->
<modelVersion>4.0.0</modelVersion>
<groupId>jboss</groupId>
<version>5.0-SNAPSHOT</version>
<artifactId>jbossas</artifactId>
<name>JBoss Top Level Build</name>
<packaging>pom</packaging>
<!-- properties can be defined in this fashion -->
<properties>
<specification.title>JBoss</specification.title>
</properties>
<!-- you can define a list of modules to build for your project -->
<modules>
<module>../module1</module>
<module>../module2</module>
</modules>
<!-- describe the build process -->
<build>
<!-- define src and output directories, this is inherited by child builds -->
<sourceDirectory>src/main</sourceDirectory>
<outputDirectory>output/classes</outputDirectory>
<!--a plugin is how achieve a unit of work, a build is made up a series of plugins -->
<plugins>
<!-- define a custom clean plugin and configure it to include the cleaning
of an additional directory
Because this is a top level build, the plugins we define here will be inherited
by the builds in the child modules -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>${basedir}/output</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<!-- define how we want compilation to take place
here, we accept most of the defaults but say that we want the
optimization flag set, and define the source and target to be 1.4,
these setting will be inherited by child projects -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
<configuration>
<optimize>true</optimize>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
<!-- define that we wish to create src jars -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<inherited>true</inherited>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- This section defines plugins which will be used in the build.
Placing plugin descriptions here will give them default values, but
will not dictate that they will be used by child builds.
This section allows us to lock down plugin versions which are used. -->
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- define a repository used to retrieve dependencies from -->
<repositories>
<repository>
<id>central</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.com/maven2</url>
<layout>default</layout>
</repository>
</repositories>
<!-- define the plugin repository we wish to use -->
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>jboss plugin repository</name>
<url>http://repository.jboss.com/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>lsu.edu</id>
<name>LSU maven2 mirror</name>
<url>http://ibiblio.lsu.edu/main/pub/packages/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- the dependencyManagement section allows us to define dependencies
which may be used by subprojects, we specify the version here, this does
not however dictate that the subproject will use the dependency, they must
request it -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

-

Child Level Pom

The child level pom generally should define which dependencies are needed to build, any custom build procedures (e.g. rmic) and how to build the output artifact The following is a template pom.xml:

Developer steps

So for each project, to create a build file, you will do the following:

Create a pom.xml from the child pom template

Add the appopriate thirdparty dependencies

Add the appropriate project dependencies

Add and configure any additional plugins as needed.

-

How do I use maven?

Once you have created a pom file you will want to build your project. We now need to understand the concept of the maven lifecycle. For each build maven has a lifecycle. This lifecycle is divided into stages (e.g. validate, compile, tests, packaging).