Java Reference
In-Depth Information
Then you're free to build the software on any other machine. There's no need to bun-
dle the dependencies with your project and so forth.
But Maven introduced also the concept of the local repository. This is a directory on
your hard disk (~/.m2/repository/ on
UNIX
and C:\Documents and Settings\<User-
Name>\.m2\repository\ on Windows) where Maven keeps the artifacts that it has just
downloaded from the central repository. Also, after you've built your project, your arti-
facts are installed in the local repository for later use by some other projects—simple
and neat.
10.1.3
Maven build lifecycles
Another strong principle in Maven is the
build lifecycle
. The Maven project is built
around the idea of defining the process of building, testing, and distributing a partic-
ular artifact. Maven projects can produce
only one
artifact. This way we can use Maven
for building the project's artifact, or cleaning the project's directory structure, or gen-
erating the project's documentation. The activities we use Maven for define the three
built-in lifecycles of Maven:
Default
—For generating the project's artifact
■
Clean
—For cleaning the project
■
Site
—For generating the project's documentation
■
Each of these lifecycles comprises several
phases
, and in order to pass through a cer-
tain lifecycle, the build must follow its phases.
Here's a list of all the phases of the default lifecycle:
Validate
—Validate that the project is correct and all necessary information
is available.
■
Compile
—Compile the source code of the project.
■
Te s t
—Test the compiled source code using a suitable unit-testing framework.
These tests should not require the code to be packaged or deployed.
■
Package
—Package the compiled code in its distributable format, such as a
JAR
.
■
Integration test
—Process and deploy the package if necessary into an environ-
ment where integration tests can be run.
■
Verify
—Run any checks to verify that the package is valid and meets quality
criteria.
■
Install
—Install the package into the local repository for use as a dependency in
other projects locally.
■
Deploy
—In an integration or release environment, copy the final package to the
remote repository for sharing with other developers and projects.
■
If you remember, with Ant we had targets with almost the same names. And yes, the
targets in Ant are the analogue of the phases in Maven, with one exception. In Ant
you
write the targets and
you
specify which target depends on which other target.
With Maven, we see again the convention-over-configuration principle here. These