Maven is the number one build tool used by developers, and it has been there for more than a decade. Maven stands out among other build tools due to its extremely extensible architecture, which is built on top of the concept convention over configuration. This, in fact, has made Maven the de-facto tool to manage and build Java projects. It's being used widely by many open source Java projects under the Apache Software Foundation, SourceForge, Google Code, and many more.
This book provides a step-by-step guide, showing the readers how to use Apache Maven in an optimal way to address enterprise build requirements. Following the book, readers will be able to gain a thorough understanding of the following key areas:
How to get started with Apache Maven, applying Maven best practices in order to design a build system to improve a developer's productivity
How to customize the build process to suit it exactly to your enterprise's needs by using appropriate Maven plugins, lifecycles, and archetypes
How to troubleshoot build issues with greater confidence
How to design the build in a way that avoids any maintenance nightmares with proper dependency management
How to optimize Maven configuration settings
How to build your own distribution archive using Maven assemblies
Chapter 1, Apache Maven Quick Start, focuses on building a basic foundation around Maven to get started. It starts by explaining the basic steps to install and configure Maven on Ubuntu, Mac OS X, and Microsoft Windows operating systems. The latter part of the chapter covers some of the common useful Maven tips and tricks.
Chapter 2, Understanding the Project Object Model (POM), focuses on the Maven Project Object Model (POM) and how to adhere to the industry-wide accepted best practices to avoid maintenance nightmares. The key elements of a POM file, POM hierarchy and inheritance, managing dependencies, and related topics are covered here.
Chapter 3, Maven Archetypes, focuses on how Maven archetypes provide a way of reducing repetitive work in building Maven projects. There are thousands of archetypes out there that are available publicly to help you build different types of projects. This chapter covers a commonly used set of archetypes.
Chapter 4, Maven Plugins, covers some of the most commonly used Maven plugins and then explains how plugins are discovered and executed. Maven only provides a build framework, while the Maven plugins perform the actual tasks. Maven has a large, rich set of plugins, and the chances are very small that you will have to write your own custom plugin.
Chapter 5, Build Lifecycles, explains how the three standard lifecycles work and how we can customize them. Later in the chapter, we discuss how to develop our own lifecycle extensions.
Chapter 6, Maven Assemblies, covers real-world examples of how to use the Maven assembly plugin in detail, and finally concludes with an end-to-end sample Maven project.
Chapter 7, Best Practices, looks at and highlights some of the best practices to be followed in a large-scale development project with Maven. It is always recommended to follow the best practices since it will drastically improve developer productivity and reduce any maintenance nightmares.
To follow the examples that are presented in this book, you will need the following software:
Apache Maven 3.3.x, which you can find at http://maven.apache.org/download.cgi
Java 1.7+ SDK, which you can find at http://www.oracle.com/technetwork/java/javase/downloads/index.html
Operating Systems: Windows, Linux, or Mac OS X.
The book is ideal for experienced developers who are already familiar with build automation, but want to learn how to use Maven and apply its concepts to the most difficult scenarios in build automation.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "When you type mvn clean install
, Maven will execute all the phases in the default lifecycle up to install
(including the install
phase)."
A block of code is set as follows:
<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> [...] </build> [...] </project>
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
<project> [...] <build> [...] <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> [...] </build> [...] </project>
Any command-line input or output is written as follows:
$ mvn install:install
New terms and important words are shown in bold.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>
, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>
, and we will do our best to address the problem.