Maven: The Complete Reference

Table of Contents

Learning Maven can be a daunting and frustrating task. While there are a number of references for Maven online, there is no single, well-written narrative for introducing Maven that can serve as both an authoritative reference and an introduction. Sonatype maintains two books focused on Maven: an example-driven introduction to Maven, "Maven by Example" and this reference book. If you are new to Maven, you are encouraged to read "Maven by Example" as it will guide you through the first steps you'll take with Maven.

Authors

Tim O'Brien Manfred Moser John Casey Brian Fox Jason Van Zyl Eric Redmond Larry Shatzer

Preface
1. Acknowledgements
1. Introducing Apache Maven
1.1. Maven… What is it?
1.2. Convention Over Configuration
1.3. A Common Interface
1.4. Universal Reuse through Maven Plugins
1.5. Conceptual Model of a "Project"
1.6. Is Maven an alternative to XYZ?
1.7. Comparing Maven with Ant
2. Installing Maven
2.1. Verify your Java Installation
2.2. Downloading Maven
2.3. Installing Maven
2.3.1. Installing Maven on Mac OSX
2.3.2. Installing Maven on Microsoft Windows
2.3.3. Installing Maven on Linux
2.3.4. Installing Maven on FreeBSD or OpenBSD
2.4. Testing a Maven Installation
2.5. Maven Installation Details
2.5.1. User-specific Configuration and Repository
2.5.2. Upgrading a Maven Installation
2.5.3. Upgrading from Maven 1.x to Maven 2.x
2.6. Uninstalling Maven
2.7. Getting Help with Maven
2.8. About the Apache Software License
3. The Project Object Model
3.1. Introduction
3.2. The POM
3.2.1. The Super POM
3.2.2. The Simplest POM
3.2.3. The Effective POM
3.2.4. Real POMs
3.3. POM Syntax
3.3.1. Project Versions
3.3.2. Property References
3.4. Project Dependencies
3.4.1. Dependency Scope
3.4.2. Optional Dependencies
3.4.3. Dependency Version Ranges
3.4.4. Transitive Dependencies
3.4.5. Conflict Resolution
3.5. Project Relationships
3.5.1. More on Coordinates
3.5.2. Project Inheritance
3.6. POM Best Practices
3.6.1. Grouping Dependencies
3.6.2. Multi-module vs. Inheritance
4. The Build Lifecycle
4.1. Introduction
4.1.1. Clean Lifecycle (clean)
4.1.2. Default Lifecycle (default)
4.1.3. Site Lifecycle (site)
4.2. Package-specific Lifecycles
4.2.1. JAR
4.2.2. POM
4.2.3. Maven Plugin
4.2.4. EJB
4.2.5. WAR
4.2.6. EAR
4.2.7. Other Packaging Types
4.3. Common Lifecycle Goals
4.3.1. Process Resources
4.3.2. Compile
4.3.3. Process Test Resources
4.3.4. Test Compile
4.3.5. Test
4.3.6. Install
4.3.7. Deploy
5. Build Profiles
5.1. What Are They For?
5.1.1. What is Build Portability
5.1.2. Selecting an Appropriate Level of Portability
5.2. Portability through Maven Profiles
5.2.1. Overriding a Project Object Model
5.3. Profile Activation
5.3.1. Activation Configuration
5.3.2. Activation by the Absence of a Property
5.4. Listing Active Profiles
5.5. Tips and Tricks
5.5.1. Common Environments
5.5.2. Protecting Secrets
5.5.3. Platform Classifiers
5.6. Summary
6. Running Maven
6.1. Maven Command Line Options
6.1.1. Defining Properties
6.1.2. Getting Help
6.1.3. Using Build Profiles
6.1.4. Displaying Version Information
6.1.5. Running in Offline Mode
6.1.6. Using a Custom POM or Custom Settings File
6.1.7. Encrypting Passwords
6.1.8. Dealing with Failure
6.1.9. Controlling Maven’s Verbosity
6.1.10. Running Maven in Batch Mode
6.1.11. Downloading and Verifying Dependencies
6.1.12. Non-recursive Builds
6.2. Using Advanced Reactor Options
6.2.1. Advanced Reactor Options Example Project
6.2.2. Resuming Builds
6.2.3. Specifying a Subset of Projects
6.2.4. Making a Subset of Projects
6.2.5. Making Project Dependents
6.2.6. Resuming a "make" build
6.3. Using the Maven Help Plugin
6.3.1. Describing a Maven Plugin
7. Maven Configuration
7.1. Configuring Maven Plugins
7.1.1. Plugin Configuration Parameters
7.1.2. Adding Plugin Dependencies
7.1.3. Setting Global Plugin Parameters
7.1.4. Setting Execution Specific Parameters
7.1.5. Setting Default Command Line Execution Parameters
7.1.6. Setting Parameters for Goals Bound to Default Lifecycle
8. Maven Assemblies
8.1. Introduction
8.2. Assembly Basics
8.2.1. Predefined Assembly Descriptors
8.2.2. Building an Assembly
8.2.3. Assemblies as Dependencies
8.2.4. Assembling Assemblies via Assembly Dependencies
8.3. Overview of the Assembly Descriptor
8.4. The Assembly Descriptor
8.4.1. Property References in Assembly Descriptors
8.4.2. Required Assembly Information
8.5. Controlling the Contents of an Assembly
8.5.1. Files Section
8.5.2. FileSets Section
8.5.3. Default Exclusion Patterns for
8.5.4. dependencySets Section
8.5.5. moduleSets Sections
8.5.6. Repositories Section
8.5.7. Managing the Assembly’s Root Directory
8.5.8. componentDescriptors and
8.6. Best Practices
8.6.1. Standard, Reusable Assembly Descriptors
8.6.2. Distribution (Aggregating) Assemblies
8.7. Summary
9. Properties and Resource Filtering
9.1. Introduction
9.2. Maven Properties
9.2.1. Maven Project Properties
9.2.2. Maven Settings Properties
9.2.3. Environment Variable Properties
9.2.4. Java System Properties
9.2.5. User-defined Properties
9.3. Resource Filtering
10. Site Generation
10.1. Introduction
10.2. Building a Project Site with Maven
10.3. Customizing the Site Descriptor
10.3.1. Customizing the Header Graphics
10.3.2. Customizing the Navigation Menu
10.4. Site Directory Structure
10.5. Writing Project Documentation
10.5.1. APT Example
10.5.2. FML Example
10.6. Deploying Your Project Website
10.6.1. Configuring Server Authentication
10.6.2. Configuring File and Directory Modes
10.7. Customizing Site Appearance
10.7.1. Customizing the Site CSS
10.7.2. Create a Custom Site Template
10.7.3. Reusable Website Skins
10.7.4. Creating a Custom Theme CSS
10.8. Tips and Tricks
10.8.1. Inject XHTML into HEAD
10.8.2. Add Links under Your Site Logo
10.8.3. Add Breadcrumbs to Your Site
10.8.4. Add the Project Version
10.8.5. Modify the Publication Date Format and Location
10.8.6. Using Doxia Macros
11. Writing Plugins
11.1. Introduction
11.2. Programming Maven
11.2.1. What is Inversion of Control?
11.2.2. Introduction to Plexus
11.2.3. Why Plexus?
11.2.4. What is a Plugin?
11.3. Plugin Descriptor
11.3.1. Top-level Plugin Descriptor Elements
11.3.2. Mojo Configuration
11.3.3. Plugin Dependencies
11.4. Writing a Custom Plugin
11.4.1. Creating a Plugin Project
11.4.2. A Simple Java Mojo
11.4.3. Configuring a Plugin Prefix
11.4.4. Logging from a Plugin
11.4.5. Mojo Class Annotations
11.4.6. When a Mojo Fails
11.5. Mojo Parameters
11.5.1. Supplying Values for Mojo Parameters
11.5.2. Multi-valued Mojo Parameters
11.5.3. Depending on Plexus Components
11.5.4. Mojo Parameter Annotations
11.6. Plugins and the Maven Lifecycle
11.6.1. Executing a Parallel Lifecycle
11.6.2. Creating a Custom Lifecycle
11.6.3. Overriding the Default Lifecycle
12. Using Maven Archetypes
12.1. Introduction to Maven Archetypes
12.2. Using Archetypes
12.2.1. Using an Archetype from the Command Line
12.2.2. Using the Interactive generate Goal
12.2.3. Using an Archetype from m2eclipse
12.3. Available Archetypes
12.3.1. Common Maven Archetypes
12.3.2. Notable Third-Party Archetypes
12.4. Publishing Archetypes
13. Developing with Flexmojos
13.1. Introduction
13.2. Configuring Build Environment for Flexmojos
13.2.1. Referencing a Repository with the Flex Framework
13.2.2. Configure a Flexmojos Proxy Repository in Nexus
13.2.3. Configuring Environment to Support Flex Unit Tests
13.2.4. Adding FlexMojos to Your Maven Settings' Plugin Groups
13.3. Creating a Flex Mojos Project from an Archetype
13.3.1. Creating a Flex Library
13.3.2. Creating a Flex Application
13.3.3. Creating a Multi-module Project: Web Application with a Flex
13.4. The FlexMojos Lifecycle
13.4.1. The SWC Lifecycle
13.4.2. The SWF Lifecycle
13.5. FlexMojos Plugin Goals
13.5.1. Generating Actionscript Documentation
13.5.2. Compiling Flex Source
13.5.3. Generating Flex Builder Project Files
13.6. FlexMojos Plugin Reports
13.6.1. Generating Actionscript Documentation Report
13.7. Developing and Customizing Flexmojos
13.7.1. Get the Flexmojos Source Code
14. Android Application Development with Maven
14.1. Introduction
14.2. Configuring Build Environment for Android Development
14.2.1. Installing the Android SDK
14.2.2. Android artifact install into Maven repository
14.3. Getting Started
14.4. Creating New Projects with the Android Maven Archetypes
14.5. Using Add-Ons
14.6. Multi Module Android Projects
14.7. Using external dependencies
14.8. The Custom Lifecycle from the Android Maven Plugin
14.9. Plugin Configuration Parameters
14.10. Device Interaction
14.11. Emulator Interaction
14.12. Other Useful Android Maven Plugin Goals
14.12.1. Manifest-update
14.12.2. Zipalign
14.12.3. Help
14.13. Internal Android Maven Plugin Goals
14.14. Testing Android Application Code
14.14.1. Unit tests
14.14.2. Instrumentation tests
14.15. Native Application Builds
14.16. Tips and Tricks
14.16.1. Other Maven Plugins
14.16.2. Performing a Release Build
14.16.3. Configuring command line usage
15. Appendix: Settings Details
15.1. Quick Overview
15.2. Settings Details
15.2.1. Simple Values
15.2.2. Servers
15.2.3. Mirrors
15.2.4. Proxies
15.2.5. Profiles
15.2.6. Activation
15.2.7. Properties
15.2.8. Repositories
15.2.9. Plugin Repositories
15.2.10. Active Profiles
15.2.11. Encrypting Passwords in Maven Settings
16. Appendix: Sun Specification Alternatives
17. Creative Commons License
Copyright