Maven: The Definitive Guide

Authors

Tim O'Brien (Sonatype, Inc.) , John Casey (Sonatype, Inc.) , Brian Fox (Sonatype, Inc.) , Bruce Snyder (Sonatype, Inc.) , Jason Van Zyl (Sonatype, Inc.)

Authors

Eric Redmond ()

Abstract

Maven: The Definitive Guide is a book about Apache Maven.


Copyright
1. Creative Commons BY-ND-NC
Foreword: 0.6-SNAPSHOT
1. Revision History
1.1. Changes in Edition 0.5
1.2. Changes in Edition 0.4
Preface
1. How to Use this Book
2. Your Feedback
3. Font Conventions
4. Maven Writing Conventions
5. 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
1.8. Summary
2. Installing and Running 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.1.1. Installing Maven on OSX using MacPorts
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. Using the Maven Help Plugin
2.8.1. Describing a Maven Plugin
2.9. About the Apache Software License
I. Maven by Example
3. A Simple Maven Project
3.1. Introduction
3.1.1. Downloading this Chapter's Example
3.2. Creating a Simple Project
3.3. Building a Simple Project
3.4. Simple Project Object Model
3.5. Core Concepts
3.5.1. Maven Plugins and Goals
3.5.2. Maven Lifecycle
3.5.3. Maven Coordinates
3.5.4. Maven Repositories
3.5.5. Maven's Dependency Management
3.5.6. Site Generation and Reporting
3.6. Summary
4. Customizing a Maven Project
4.1. Introduction
4.1.1. Downloading this Chapter's Example
4.2. Defining the Simple Weather Project
4.2.1. Yahoo! Weather RSS
4.3. Creating the Simple Weather Project
4.4. Customize Project Information
4.5. Add New Dependencies
4.6. Simple Weather Source Code
4.7. Add Resources
4.8. Running the Simple Weather Program
4.8.1. The Maven Exec Plugin
4.8.2. Exploring Your Project Dependencies
4.9. Writing Unit Tests
4.10. Adding Test-scoped Dependencies
4.11. Adding Unit Test Resources
4.12. Executing Unit Tests
4.12.1. Ignoring Test Failures
4.12.2. Skipping Unit Tests
4.13. Building a Packaged Command Line Application
4.13.1. Attaching the Assembly Goal to the Package Phase
5. A Simple Web Application
5.1. Introduction
5.1.1. Downloading this Chapter's Example
5.2. Defining the Simple Web Application
5.3. Creating the Simple Web Project
5.4. Configuring the Jetty Plugin
5.5. Adding a Simple Servlet
5.6. Adding J2EE Dependencies
5.7. Conclusion
6. A Multi-module Project
6.1. Introduction
6.1.1. Downloading this Chapter's Example
6.2. The Simple Parent Project
6.3. The Simple Weather Module
6.4. The Simple Web Application Module
6.5. Building the Multimodule Project
6.6. Running the Web Application
7. Multi-module Enterprise Project
7.1. Introduction
7.1.1. Downloading this Chapter's Example
7.1.2. Multi-module Enterprise Project
7.1.3. Technology Used in this Example
7.2. The Simple Parent Project
7.3. The Simple Model Module
7.4. The Simple Weather Module
7.5. The Simple Persist Module
7.6. The Simple Web Application Module
7.7. Running the Web Application
7.8. The Simple Command Module
7.9. Running the Simple Command
7.10. Conclusion
7.10.1. Programming to Interface Projects
8. Optimizing and Refactoring POMs
8.1. Introduction
8.2. POM Cleanup
8.3. Optimizing Dependencies
8.4. Optimizing Plugins
8.5. Optimizing with the Maven Dependency Plugin
8.6. Final POMs
8.7. Conclusion
II. Maven Reference
9. The Project Object Model
9.1. Introduction
9.2. The POM
9.2.1. The Super POM
9.2.2. The Simplest POM
9.2.3. The Effective POM
9.2.4. Real POMs
9.3. POM Syntax
9.3.1. Project Versions
9.3.1.1. Version Build Numbers
9.3.1.2. SNAPSHOT Versions
9.3.1.3. LATEST and RELEASE Versions
9.3.2. Property References
9.4. Project Dependencies
9.4.1. Dependency Scope
9.4.2. Optional Dependencies
9.4.3. Dependency Version Ranges
9.4.4. Transitive Dependencies
9.4.4.1. Transitive Dependencies and Scope
9.4.5. Conflict Resolution
9.4.6. Dependency Management
9.5. Project Relationships
9.5.1. More on Coordinates
9.5.2. Multi-module Projects
9.5.3. Project Inheritance
9.6. POM Best Practices
9.6.1. Grouping Dependencies
9.6.2. Multi-module vs. Inheritance
9.6.2.1. Simple Project
9.6.2.2. Multi-module Enterprise Project
9.6.2.3. Prototype Parent Projects
10. The Build Lifecycle
10.1. Introduction
10.1.1. Clean Lifecycle (clean)
10.1.2. Default Lifecycle (default)
10.1.3. Site Lifecycle (site)
10.2. Package-specific Lifecycles
10.2.1. JAR
10.2.2. POM
10.2.3. Maven Plugin
10.2.4. EJB
10.2.5. WAR
10.2.6. EAR
10.2.7. Other Packaging Types
10.3. Common Lifecycle Goals
10.3.1. Process Resources
10.3.2. Compile
10.3.3. Process Test Resources
10.3.4. Test Compile
10.3.5. Test
10.3.6. Install
10.3.7. Deploy
11. Build Profiles
11.1. What Are They For?
11.1.1. What is Build Portability
11.1.1.1. Non-Portable Builds
11.1.1.2. Environment Portability
11.1.1.3. Organizational (In-House) Portability
11.1.1.4. Wide (Universal) Portability
11.1.2. Selecting an Appropriate Level of Portability
11.2. Portability through Maven Profiles
11.2.1. Overriding a Project Object Model
11.3. Profile Activation
11.3.1. Activation Configuration
11.3.2. Activation by the Absence of a Property
11.4. Listing Active Profiles
11.5. Tips and Tricks
11.5.1. Common Environments
11.5.2. Protecting Secrets
11.5.3. Platform Classifiers
11.6. Summary
12. Maven Assemblies
12.1. Introduction
12.2. Assembly Basics
12.2.1. Predefined Assembly Descriptors
12.2.2. Building an Assembly
12.2.3. Assemblies as Dependencies
12.2.4. Assembling Assemblies via Assembly Dependencies
12.3. Overview of the Assembly Descriptor
12.4. The Assembly Descriptor
12.4.1. Property References in Assembly Descriptors
12.4.2. Required Assembly Information
12.5. Controlling the Contents of an Assembly
12.5.1. Files Section
12.5.2. FileSets Section
12.5.3. Default Exclusion Patterns for fileSets
12.5.4. dependencySets Section
12.5.4.1. Customizing Dependency Output Location
12.5.4.2. Interpolation of Properties in Dependency Output Location
12.5.4.3. Including and Excluding Dependencies by Scope
12.5.4.4. Fine Tuning: Dependency Includes and Excludes
12.5.4.5. Transitive Dependencies, Project Attachments, and Project Artifacts
12.5.4.6. Advanced Unpacking Options
12.5.4.7. Summarizing Dependency Sets
12.5.5. moduleSets Sections
12.5.5.1. Module Selection
12.5.5.2. Sources Section
12.5.5.3. Interpolation of outputDirectoryMapping in moduleSets
12.5.5.4. Binaries section
12.5.5.5. moduleSets, Parent POMs and the binaries Section
12.5.6. Repositories Section
12.5.7. Managing the Assembly’s Root Directory
12.5.8. componentDescriptors and containerDescriptorHandlers
12.6. Best Practices
12.6.1. Standard, Reusable Assembly Descriptors
12.6.2. Distribution (Aggregating) Assemblies
12.7. Summary
13. Properties and Resource Filtering
13.1. Introduction
13.2. Maven Properties
13.2.1. Maven Project Properties
13.2.2. Maven Settings Properties
13.2.3. Environment Variable Properties
13.2.4. Java System Properties
13.2.5. User-defined Properties
13.3. Resource Filtering
14. Maven and Eclipse: m2eclipse
15. Site Generation
15.1. Introduction
15.2. Building a Project Site with Maven
15.3. Customizing the Site Descriptor
15.3.1. Customizing the Header Graphics
15.3.2. Customizing the Navigation Menu
15.4. Site Directory Structure
15.5. Writing Project Documentation
15.5.1. APT Example
15.5.2. FML Example
15.6. Deploying Your Project Website
15.6.1. Configuring Server Authentication
15.6.2. Configuring File and Directory Modes
15.7. Customizing Site Appearance
15.7.1. Customizing the Site CSS
15.7.2. Create a Custom Site Template
15.7.3. Reusable Website Skins
15.7.4. Creating a Custom Theme CSS
15.7.5. Customizing Site Templates in a Skin
15.8. Tips and Tricks
15.8.1. Inject XHTML into HEAD
15.8.2. Add Links under Your Site Logo
15.8.3. Add Breadcrumbs to Your Site
15.8.4. Add the Project Version
15.8.5. Modify the Publication Date Format and Location
15.8.6. Using Doxia Macros
16. Repository Management with Nexus
17. Writing Plugins
17.1. Introduction
17.2. Programming Maven
17.2.1. What is Inversion of Control?
17.2.2. Introduction to Plexus
17.2.3. Why Plexus?
17.2.4. What is a Plugin?
17.3. Plugin Descriptor
17.3.1. Top-level Plugin Descriptor Elements
17.3.2. Mojo Configuration
17.3.3. Plugin Dependencies
17.4. Writing a Custom Plugin
17.4.1. Creating a Plugin Project
17.4.2. A Simple Java Mojo
17.4.3. Configuring a Plugin Prefix
17.4.4. Logging from a Plugin
17.4.5. Mojo Class Annotations
17.4.6. When a Mojo Fails
17.5. Mojo Parameters
17.5.1. Supplying Values for Mojo Parameters
17.5.2. Multi-valued Mojo Parameters
17.5.3. Depending on Plexus Components
17.5.4. Mojo Parameter Annotations
17.6. Plugins and the Maven Lifecycle
17.6.1. Executing a Parallel Lifecycle
17.6.2. Creating a Custom Lifecycle
17.6.3. Overriding the Default Lifecycle
18. Writing Plugins in Alternative Languages
18.1. Writing Plugins in Ant
18.2. Creating an Ant Plugin
18.3. Writing Plugins in JRuby
18.3.1. Creating a JRuby Plugin
18.3.2. Ruby Mojo Implementations
18.3.3. Logging from a Ruby Mojo
18.3.4. Raising a MojoError
18.3.5. Referencing Plexus Components from JRuby
18.4. Writing Plugins in Groovy
18.4.1. Creating a Groovy Plugin
19. Using Maven Archetypes
19.1. Introduction to Maven Archetypes
19.2. Using Archetypes
19.2.1. Using an Archetype from the Command Line
19.2.2. Using the Interactive generate Goal
19.2.3. Using an Archetype from m2eclipse
19.3. Available Archetypes
19.3.1. Common Maven Archetypes
19.3.1.1. maven-archetype-quickstart
19.3.1.2. maven-archetype-webapp
19.3.1.3. maven-archetype-mojo
19.3.2. Notable Third-Party Archetypes
19.3.2.1. AppFuse
19.3.2.2. Confluence and JIRA plugins
19.3.2.3. Wicket
19.4. Publishing Archetypes
20. Developing with Flexmojos
20.1. Introduction
20.2. Configuring Build Environment for Flexmojos
20.2.1. Referencing a Repository with the Flex Framework
20.2.1.1. Using Sonatype's Repository Directly
20.2.1.2. Proxying Sonatype's Repository with Nexus
20.2.2. Configuring Environment to Support Flex Unit Tests
20.2.3. Adding FlexMojos to Your Maven Settings' Plugin Groups
20.3. Creating a Flex Mojos Project from an Archetype
20.3.1. Creating a Flex Library
20.3.2. Creating a Flex Application
20.3.3. Creating a Multi-module Project: Web Application with a Flex Dependency
20.4. The FlexMojos Lifecycle
20.4.1. The SWC Lifecycle
20.4.2. The SWF Lifecycle
20.5. FlexMojos Plugin Goals
20.5.1. Generating Actionscript Documentation
20.5.1.1. Configuring the asdoc Goal
20.5.2. Compiling Flex Source
20.5.2.1. Common Compilation Parameters for Compilation Goals
20.5.2.2. Configuring the compile-swc Goal
20.5.2.3. Configuring the compile-swf Goal
20.5.3. Unit Testing Flex
20.5.3.1. Configuring the test-compile Goal
20.5.3.2. Configuring the test-run Goal
20.5.4. Generating Flex Builder Project Files
20.5.4.1. Configuring the flexbuilder Goal
20.6. FlexMojos Plugin Reports
20.6.1. Generating Actionscript Documentation Report
20.7. Developing and Customizing Flexmojos
20.7.1. Get the Flexmojos Source Code
A. Appendix: Settings Details
A.1. Quick Overview
A.2. Settings Details
A.2.1. Simple Values
A.2.2. Servers
A.2.3. Mirrors
A.2.4. Proxies
A.2.5. Profiles
A.2.6. Activation
A.2.7. Properties
A.2.8. Repositories
A.2.9. Plugin Repositories
A.2.10. Active Profiles
A.2.11. Encrypting Passwords in Maven Settings
B. Appendix: Sun Specification Alternatives