Apache Maven

From Wikipedia, the free encyclopedia

Jump to: navigation, search
Apache Maven
Developed by Apache Software Foundation
Latest release 2.1.0 / 2009-3-21; 13 days ago
Written in Java
Operating system Cross-platform
Development status Active
Type Build Tool
License Apache License 2.0
Website http://maven.apache.org
For other uses of the word Maven see: Maven (disambiguation)

Maven is a software tool for Java project management and build automation created by Sonatype's Jason van Zyl in 2002. It is similar in functionality to the Apache Ant tool (and to a lesser extent, PHP's PEAR and Perl's CPAN), but has a simpler build configuration model, based on an XML format. Maven is hosted by the Apache Software Foundation, where it was formerly part of the Jakarta Project.

Maven uses a construct known as a Project Object Model (POM) to describe the software project being built, its dependencies on other external modules and components, and the build order. It comes with pre-defined targets for performing certain well defined tasks such as compilation of code and its packaging.

A key feature of Maven is that it is network-ready. The core engine can dynamically download plug-ins from a repository, the same repository that provides access to many versions of different Open Source Java projects, from Apache and other organizations and developers. This repository and its reorganized successor, the Maven 2 repository, strives to be the de facto distribution mechanism for Java applications, but its adoption has been slow. Maven provides built in support not just for retrieving files from this repository, but to upload artifacts at the end of the build. A local cache of downloaded artifacts acts as the primary means of synchronizing the output of projects on a local system.

Maven is built using a plugin-based architecture that allows it to make use of any application controllable through standard input. Theoretically, this would allow anyone to write plugins to interface with build tools (compilers, unit test tools, etc.) for any other language. In reality, support and use for languages other than Java has been minimal. Currently a plugin for the .Net framework exists and is maintained [1], and a C/C++ native plugin was at one time maintained for Maven 1.[2]

Contents

[edit] Theory

[edit] Convention over configuration

The overarching philosophy of Maven is standardization of builds by embracing Convention over Configuration in order to utilize existing patterns in software production. This strategy necessarily restricts project variability to a large degree, which is reflected in Maven's exhortation to adhere to its project model.[3] While readily suitable for new projects, existing complex projects may be simply unsuitable for Maven usage.[4] The restrictiveness of the project layout convention was made somewhat more configurable with the release of Maven 2.

[edit] Reuse

Maven is built around the idea of reuse and, more specifically, the reuse of build logic. As projects are typically and frequently built in similar patterns, a logical choice would be to reuse the build processes. The main idea is not to reuse the code or functionality (like Apache Ant), but to simply change the configuration of already written code. That's the main difference between Apache Ant and Apache Maven: one is a library of good and useful utilities and functions, while the other is a configurable and highly pluggable framework.[vague]

Although Maven is somewhat configurable, historically the Maven project has heavily emphasized that users should adhere to their concept of a standard project model as much as possible.

[edit] Life cycle

The parts of the main Maven project life cycle are:

  • compile
  • test
  • package
  • install
  • deploy

The idea is that, for any goal, all the previous goals are also run except if they have already been successfully accomplished and no changes have been made on the project. For example, when running mvn install Maven will check if mvn package has successfully been run (the jar exists in target/), in which case it will not be run again.

Also, there are some goals that are outside the life cycle that can be called, but Maven assumes that these goals are not part of the default life-cycle (don't have to be always performed). These goals are:

  • clean
  • assembly:assembly
  • site
  • site-deploy
  • etc...

But these goals can be added to the default life cycle through the project's POM.

[edit] The POM

[edit] IDE Integration

Maven replaces the IDE in the build process so its integration with the different Java IDEs is very important. There are Maven plugins for creating IDE configuration files from the POMs. Currently supported:

[edit] Assembly descriptor

[edit] Examples

Maven projects are created with a command line of the following kind:

 mvn archetype:create -DgroupId="com.some.company" -DartifactId="some-project" -Dversion="0.0.1"

Maven can create an Eclipse project descriptor with the following command:

mvn eclipse:eclipse 

[edit] References

  1. ^ NET Maven Plugin - .NET Maven Plugin
  2. ^ Maven Native Plugin - Maven Native Plug-in
  3. ^ Maven - History of Maven
  4. ^ What is Maven at apache.org

[edit] Books

[edit] See also

[edit] External links

Personal tools