Apache Maven 2 Effective Implementation - Porter Brett - E-Book

Apache Maven 2 Effective Implementation E-Book

Porter Brett

0,0
20,73 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

In Detail

By building up a sample application, this book guides developers painlessly through building a project with Maven. This book shows you how to combine Maven with Continuum and Archiva, which will allow you to build an efficient, secure application and make developing in a team easy.

You may already be aware of the pitfalls of 'integration hell' caused by changed code being submitted to repositories by a number of developers. When you implement Continuum in your build, you can easily perform continuous integration, avoiding timely rework and reducing cost and valuable time. You will be able to use Maven more efficiently in a team after you learn how to set up Archiva, Apache's repository manager.

It's easy to quickly get to work with Maven and get the most out of its related tools when you follow the sequential coverage of the sample application in this book. A focus on team environments ensures that you will avoid the pitfalls that are all too common when working in a team. Soon, by learning the best practices of working with Maven, you will have built an effective, secure Java application.

Create a secure, efficient, application using Apache Maven, Continuum and Archiva with this step-by-step guide for Java developers

Approach

All material in the book will be worked through by example, building up a sample application. It is intended to be read through in sequence, though once complete, should serve as a suitable reference for certain cases that can be referred to directly.

Who this book is for

This book is for Java developers who want to get started with Apache Maven. If you are tasked with build automation in your company, this book will help you to quickly and easily get started with Maven in order to improve the efficiency of your builds.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 600

Veröffentlichungsjahr: 2009

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Apache Maven 2 Effective Implementation
Credits
About the Authors
About the Reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code for the book
Errata
Piracy
Questions
1. Maven in a Nutshell
A whirlwind tour
Installing Maven
Creating a new project from an archetype
Building the project
Reusing builds
Adding dependencies
Adding functionality through plugins
Adding resources
Running tests
Getting help
Enhancing the development process
Viewing detailed project information
Multiple module builds
What if I need to convert an existing project?
Summary
2. Staying in Control with Archiva
Importance of a repository manager
Installing Archiva
Separating your repositories
Hooking up Maven with Archiva
Setting up a proxy
Configuring your settings.xml
Building your project
Searching for artifacts in Archiva
Deploying from Maven
Creating a new user
Configuring and deploying from Maven
Deploying via web form
Summary
3. Building an Application Using Maven
Introducing the sample project
Setting up a multi-module build
Creating the parent POM
Creating the modules
Dependency management
Fleshing out the example application
Creating an organization POM
Configuring basic reports
Preparing for non-code modules
Creating a modules tree
Adding a documentation module
Building the site automatically
Assembling the site for distribution
Adding site resources
Adding a skin
Distributing the application
Generating the runtime environment with the App Assembler plugin
Generating the assembly archive
Adding the documentation to the distribution archive
Summary
4. Application Testing with Maven
Types of testing in Maven
Unit testing (or code testing)
Integration testing (or module testing)
Functional and other types of testing
Working with tests
Surefire plugin configuration
Controlling the execution of tests
Inclusion and exclusion of tests
Running specific tests from the command line
Skipping tests temporarily
Producing a report for the test results
Reviewing test coverage
Coverage and multimodule projects
Integration, functional, and other testing
Running integration tests using naming patterns
Operating the Selenium server
Deploying the application to a container
Simplifying test grouping with TestNG
Using a separate integration test module
Altering integration tests with profiles
Using TestNG parameters
Measuring coverage for integration tests
Summary
5. Reporting and Checks
Review: Example application
Constructing the developer's site
Maven reports
Adding reports to the project
Configuring plugins for both reporting and the build
Configuring reports in the site life cycle
Setting up quality checks
Setting a minimum coverage requirement
Best practices for configuring coverage checks
Reporting and quality tools
Dependencies
Javadoc
Checkstyle
PMD
FindBugs
Clirr
Other tools
Reporting best practices
Choosing reports
Site deployment
Introducing and selecting failure thresholds
Tying it all together
Dashboard plugin
Sonar
Summary
6. Useful Maven Plugins
The Remote Resources plugin
Creating a Remote Resource bundle
Processing Remote Resources in a project
The Build Number plugin
The Shade plugin
Building a standalone artifact
Shading dependencies
The Build Helper plugin
Adding source directories
Attaching arbitrary artifacts
Other goals
The AntRun plugin and scripting languages
Running simple tasks
Interacting with the Maven project
Converting Ant or Maven 1 builds
Maven plugins written in Ant
Other scripting languages
The Exec plugin
Adding the Exec plugin to the Build life cycle
Running the Exec plugin standalone
Summary
7. Maven Best Practices
Preparing the development environment
Maven installation and user settings
Encrypting server passwords
Project settings
Configuring repositories
Keeping it simple
Using conventions
Using inheritance
Decomposing the build into modules
Aligning the source structure
Selecting group and artifact identifiers
Building modules together
Each module should be independently useful
Watching the dependencies
Separating API from implementation
Trimming dependencies
Dependency version management
Profiles and pipelining
Scripting and writing plugins
Creating and using archetypes
Build portability
Setting expectations
Hard coding
Portable profiles
Portable artifacts
Resource filtering
Shared resources
Build reproducibility
Summary
8. Continuum: Ensuring the Health of your Source Code
Knowing when your build breaks
Setting up Continuum
Setting up a source repository
Installing prerequisites
Installing and configuring Continuum
Using Continuum
At a glance
The build queues
The build definition
Project group build definition
Project build definition
The notifiers
Different types of notifiers
Configuring notifiers in Maven
The Build results
Dependency changes
Installations and build environments
Installations
Build environments
Summary
9. Continuum in Depth
Releasing projects
Release early, release often
Maven release process
Release profile
Releasing projects using Continuum
Preparing a release
Finalizing a release
Viewing release history
Other types of releases
Troubleshooting releases in Continuum
Build pipelining and multiple build definitions
Parallel builds
How it works
Configuring parallel builds
Distributed builds
Master and slave
Configuring distributed builds
Doing project releases on a build agent
Maintenance
Configuring multiple local repositories
Cleaning up local repositories
Cleaning up directories
Summary
10. Archiva in a Team
Roles and permissions
Introducing repository groups
Configuring and using repository groups
RSS feeds—discovering new artifacts in your repository
Repository level feeds
Artifact level feeds
Deleting artifacts in your repository
The Archiva reports
Repository statistics
Repository health
The Archiva consumers
What is a consumer?
Archiva's maintenance-savvy consumers
Purging outdated snapshots
Correcting Maven metadata
Creating missing checksums
Database cleanup consumers
Summary
11. Archetypes
What are Maven archetypes?
Benefits of Maven archetypes
Generating projects
From archetype:create to archetype:generate
Using archetypes within multi-module projects
Common archetypes
Maven site archetype
Maven Mojo (plugin) archetype
Maven simple J2EE archetype
The AppFuse Spring archetype
Other examples
Writing a new archetype
Creating an archetype from a skeleton
Using the custom archetype
Managing catalogs
Summary
12. Maven, Archiva, and Continuum in the Enterprise
Configuring security
A brief look at Redback
Setting up security for multiple teams in Continuum
Setting up security for multiple teams in Archiva
Additional Redback configuration
Using LDAP
Interfacing with other tools in the enterprise
Continuum web services
Building the Continuum plugin
Using Continuum's web services
Archiva web services
Building the Archiva plugin
Using Archiva's web services
Summary
A. Troubleshooting Maven
Examining Maven output
Using debug mode
Confirming the expected models
Analyzing dependencies
Download problems
B. Recent Maven Features
Server password encryption
Reactor project selection
Resuming a failed build
Building a subset of modules
The Reactor plugin
Building modules with local changes
Reconfiguring default life cycle goals
Parallel artifact resolution
C. Migrating Archiva and Continuum Data
Using a different database
Database backup and migrating between versions
Migrating Continuum
Migrating Archiva
Index

Apache Maven 2 Effective Implementation

Build and manage applications with Maven, Continuum, and Archiva

Brett Porter

Maria Odea Ching

Apache Maven 2 Effective Implementation

Build and manage applications with Maven, Continuum, and Archiva

Copyright © 2009 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2009

Production Reference: 1080909

Published by Packt Publishing Ltd.

32 Lincoln Road

Olton

Birmingham, B27 6PA, UK.

ISBN 978-1-847194-54-1

www.packtpub.com

Cover Image by Vinayak Chittar (<[email protected]>)

Credits

Authors

Maria Odea Ching

Brett Porter

Reviewers

Wendy Smoak

Emmanuel Venisse

Carsten Ziegeler

Acquisition Editor

Sarah Cullington

Development Editor

Dhiraj Chandiramani

Technical Editors

Neha Damle

John Antony

Indexer

Monica Ajmera

Rekha Nair

Editorial Team Leader

Gagandeep Singh

Project Team Leader

Priya Mukherji

Project Coordinator

Leena Purkait

Drawing Coordinator

Nilesh Mohite

Proofreader

Lesley Harrison

Production Coordinator

Shantanu Zagade

Cover Work

Shantanu Zagade

About the Authors

Maria Odea Ching grew up in Daet, a small town in the Philippines, then moved to the country's capital, Manila, when she went to college. She took up Computer Studies at De La Salle University, and graduated in 2004. She started using open source tools from her first job after graduating. From then on, she got interested in the open source philosophy. She was introduced to Apache Maven, Apache Continuum, and Apache Archiva early on in her career. She became a committer and a Project Management Committee member of Apache Maven. Eventually, she was elected as PMC Chair of Apache Archiva. She is also a member of the Apache Software Foundation.

Deng is currently a Senior Software Engineer and serves as the development lead for the Maestro project.

First, I'd like to thank Brett for the whirlwind endeavor which is this book. I'd also like to thank all our reviewers—Wendy, Emmanuel, Carsten and the Packt team, for taking the time to review and go through each chapter. You guys rock! And of course without the communities of Maven, Continuum, and Archiva, we wouldn't have anything to write about. So I'd like to thank each and everyone (committers/developers, contributors, buggers) in these respective communities. I'd also like to give special thanks to our Exist/G2iX family for their continuous support.

And last but definitely not the least, I'd like to thank my family and my boyfriend, Mike, for their unfaltering love and support and for being so patient and understanding when I have to run off to work on the book.

Brett Porter is a software developer from Sydney, Australia with a passion for development tooling and automation. Seeking a more standardized and reproducible solution to organize, build, and deploy a number of software projects across teams, he discovered an early beta of Maven 1.0 in 2003, and has been heavily involved in the development of the project since. He is a member of the Apache Maven Project Management Committee, and has conducted presentations and training on Maven and related tooling at several conferences and events. He founded the Archiva project in 2005. Brett is also a Director and Member of the Apache Software Foundation.

Brett is currently VP, Product Development at G2iX, in charge of the MaestroDev division. He and his team seek to make developers more efficient by offering support and services for development and automation tools including Apache Maven, Apache Continuum, Apache Archiva, and Selenium.

Brett was co-author of the book Better Builds with Maven, the first book to be written about the Maven 2.0 release in 2005, and has been involved in reviewing Maven: ADeveloper's Notebook and Java Power Tools.

I'd first like to thank my co-author and friend Deng for agreeing to participate in this book and lending her experience with Archiva and Continuum. I am grateful to all of the reviewers that volunteered their time to help make this the best that it can be. My great thanks go to all the members of the open source community that participate in these projects—the developers, as well as those that contribute patches, detailed bug reports, or answer questions on the user lists—not only do we build great software together, but I get the chance to work with truly remarkable individuals.

Finally, my love and thanks go to my wife Laura for sparing some more of our precious time so that I could complete this book, and for supporting me in everything I do.

About the Reviewers

Wendy Smoak is a member of The Apache Software Foundation and a committer on several open source projects, where she focuses on user support, documentation, and infrastructure. By day she is a Solutions Architect with G2iX, where her work centers around enterprise adoption of Apache Maven and related technologies.

Emmanuel Venisse has been developing and architecting J2EE applications for eleven years for bank, government, and holiday company projects. For the past three years, he's been working for Mergere/Devzuz with some other Maven contributors, like Brett and Deng, around a packaged Maven/Continuum/Archiva product—Maestro. He has been working freelance for five years. For the last six years, he's been working, in his spare time, on Maven, Continuum, and Archiva projects as a core developer, and he's the Continuum project chair. He has contributed too to Maven: A Developer's Notebook (O'Reilly) and Better build with Maven (Exist). He lives in Versailles, France, with his wife Florence and two children.

I would first like to thank my wife, Florence, without whose love and support, my work on Apache projects and this book wouldn't have been possible. I'd also like to thank my children who have to see their dad working on his laptop instead of playing with them. Finally, I'd like to thank Brett and Deng for letting me help them on this book.

Carsten Ziegeler is senior developer and software architect for JEE and portal applications at Day Software. He is a member of the Apache Software Foundation and has been participating in several open source projects for more than fifteen years. Carsten is a member of several Apache communities and project management committees such as Cocoon, Felix, Sling, Excalibur, and Portals. In addition to this, Carsten frequently writes artcles, reviews books, and can be found presenting at various conferences.

Preface

This book offers a comprehensive look at using Maven on a project, covering not only the build system itself, but how it is best used in concert with other development infrastructures such as source control, continuous integration and build servers, and an artifact repository. We cover this territory using Subversion, Apache Continuum, and Apache Archiva, respectively, though the concepts learned should apply to other comparable systems.

In many ways, this is the book we've always wanted to write about Maven, and it takes a different approach to the existing Maven titles. Rather than being a reference or documentation for the software, it takes the approach of walking through a single example application and associated infrastructure in the same way that you would develop your own projects. For this purpose, we have crafted the example application Centrepoint—a simple but functional web application composed of several modules that itself interacts with Maven, Continuum, and Archiva.

We believe this book will not only show you how to use Maven, but how to use it effectively, covering concepts and best practices that should endure beyond the current versions of Maven and apply to your development infrastructure and teams in general.

What this book covers

Chapter 1: Maven in a Nutshell is a quick overview of the fundamentals of Maven—from creating a simple Maven project to basic plugin configuration to generating sites and reports. These are demonstrated in an easy to follow step-by-step process. By the end of the chapter, you should be able to apply and use the skills that you have learned to your own project.

Chapter 2: Staying in Control with Archiva introduces you to Archiva and its role in building software. You will learn the basics of installing and configuring it for internal use. It also shows you how Archiva complements Maven and how they can be used together efficiently.

Chapter 3: Building an Application Using Maven delves into the details on how to accurately set up and build an application using Maven. The Centrepoint project is introduced in this chapter. This is the sample application that will be used for the hands-on demonstrations throughout the book. You will see how Maven enforces convention over configuration while building the Centrepoint project.

Chapter 4: Application Testing with Maven goes through the various types of automated tests that can be executed from Maven. This includes unit testing, integration testing, and testing web applications using Selenium to name a few. Instrumenting tests, implementing test coverage, and reporting of test results are also covered.

Chapter 5: Reporting and Checks shows how to configure Maven to generate project reports and incorporate them in the generated site. This chapter also tackles the basics on enforcing certain rules or checks on your code such as conforming to code styles and standards, and finding common bugs in the code while building your application.

Chapter 6: Useful Maven Plugins discusses some of the Maven plugins, both from Apache Maven and from the Codehaus Mojo project, that may be of great help in your Maven builds. The functionality of these plugins range from keeping track of the source revision number for the build to executing external applications as part of the build. You will learn to identify when to use each plugin and how to configure them properly to address your need.

Chapter 7: Maven Best Practices illustrates the effective usage of Maven. You will learn tips and tricks for setting up your development environment to managing your project dependencies to making your builds portable and reproducible. By the end of this chapter, you should be able to apply what you've learned to your next project, or even to your current one.

Chapter 8: Continuum: Ensuring the health of your source code highlights the importance of continuous integration in software development through Continuum. It covers basic installation and set up, adding projects to Continuum, and effective configuration and build scheduling, at the same time demonstrating how it works in accordance with Maven and also with Archiva.

Chapter 9: Continuum in Depth deals with releasing projects using both Maven and Continuum. The different phases involved in the release process will be covered along with a bit of troubleshooting on the side. You will also learn about building multiple projects simultaneously in Continuum through parallel and distributed builds.

Chapter 10: Archiva in a Team gives you the more advanced features of Archiva and demonstrates how to configure it for use in a team. You will learn how to control access to a repository, how to take advantage of repository groups, how to make use of its reporting feature, and how to maintain your Archiva repositories.

Chapter 11: Archetypes covers Maven archetypes. It discusses some of the archetypes available—what their purpose is and what the generated project from each archetype looks like. You will also create a custom archetype specifically for the Centrepoint application, which will be used in the last chapter.

Chapter 12: Maven, Archiva, and Continuum in the Enterprise shows how to configure Archiva and Continuum effectively for use in the corporate environment. Tips on how to set up projects and repositories across multiple projects with respect to controlling who and what can be accessed by different teams covers the first half of the chapter. The second part demonstrates the web services feature of both applications by creating plugins for the Centrepoint application and using them to get information from Archiva and Continuum.

Appendix A: Troubleshooting Maven provides techniques for troubleshooting Maven. Incorrect POM or settings configuration, and dependency and download problems are a few of the usual suspects that will be covered here.

Appendix B: Recent Maven Features discusses the new features in Maven 2.1 and above. These features include password encryption, reactor project selection, and parallel downloads of dependencies.

Appendix C: Migrating Archiva and Continuum Data illustrates how to migrate data in Archiva and Continuum when upgrading to a higher version. How to switch to a different database from the built-in one is also discussed.

What you need for this book

You need to have the following software installed:

Java 5 or aboveSubversion 1.4An outgoing mail server for some examples

We will be installing the following applications throughout the book:

Apache Maven 2.2Apache Archiva 1.2Apache Continuum 1.3

Who this book is for

This book is for Java developers who want to get started with Apache Maven. If you are tasked with build automation in your company, this book will help you to quickly and easily get started with Maven in order to improve the efficiency of your builds.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

<dependencies> <dependency> <groupId>${project.groupId}</groupId> <artifactId>model</artifactId> <version>${project.version}</version> </dependency> </dependencies>

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <forkMode>never</forkMode> </configuration> </plugin>

Any command-line input or output is written as follows:

distribution$ mvn integration-test

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an email to <[email protected]>, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

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.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/4541_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

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 would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata added to any list of existing errata. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright 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 web site 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.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.