ebook img

Apache Maven PDF

342 Pages·2011·1.21 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Apache Maven

...................................................................................................................................... Apache Maven Current version User Guide ...................................................................................................................................... The Apache Software Foundation 2011-06-08 Table of Contents i Table of Contents ....................................................................................................................................... 1 Table of Contents ........................................................... i 2 What is Maven? ............................................................. 1 3 Features ..................................................................... 3 4 FAQ .......................................................................... 4 5 Community Overview ...................................................... 11 5.1 How to Contribute ............................................................ 13 5.2 Getting Help .................................................................. 15 5.3 Issue Tracking ................................................................ 17 5.4 Source Repository ............................................................ 18 5.5 Continuous Integration ........................................................ 20 6 Running Maven ............................................................ 21 7 Maven Plugins ............................................................. 23 8 User Centre ................................................................ 31 8.1 Maven in 5 Minutes ........................................................... 32 8.2 Getting Started Guide ......................................................... 35 8.3 POM Reference ............................................................... 55 8.4 Settings Reference ............................................................ 87 8.5 Guides ....................................................................... 95 8.5.1 The Build Lifecycle ........................................................ 98 8.5.2 The POM ............................................................... 106 8.5.3 Profiles ................................................................. 120 8.5.4 Repositories ............................................................. 130 8.5.5 Standard Directory Layout ................................................ 133 8.5.6 The Dependency Mechanism .............................................. 134 8.5.7 Plugin Development ...................................................... 147 8.5.8 Configuring Plug-ins ...................................................... 150 8.5.9 The Plugin Registry ...................................................... 162 8.5.10 Plugin Prefix Resolution .................................................. 165 8.5.11 Developing Ant Plugins ................................................... 167 8.5.12 Developing Java Plugins .................................................. 178 8.5.13 Creating a Site .......................................................... 188 8.5.14 Snippet Macro ........................................................... 193 8.5.15 What is an Archetype .................................................... 195 8.5.16 Creating Archetypes ...................................................... 197 8.5.17 From Maven 1.x to Maven 2.x ............................................. 200 8.5.18 Using Maven 1.x repositories with Maven 2.x ................................ 203 8.5.19 Relocation of Artifacts .................................................... 204 8.5.20 Installing 3rd party JARs to Local Repository ................................ 206 ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. Table of Contents ii 8.5.21 Deploying 3rd party JARs to Remote Repository ............................. 207 8.5.22 Coping with Sun JARs ................................................... 208 8.5.23 Remote repository access through authenticated HTTPS ...................... 210 8.5.24 Creating Assemblies ..................................................... 212 8.5.25 Configuring Archive Plugins ............................................... 215 8.5.26 Configuring Maven ....................................................... 216 8.5.26 Mirror Settings ........................................................... 218 8.5.26 Deployment and Security Settings ......................................... 221 8.5.26 Generating Sources ...................................................... 222 8.5.26 Working with Manifests ................................................... 224 8.5.26 Maven Classloading ...................................................... 225 8.5.26 Using Multiple Modules in a Build .......................................... 227 8.5.26 Using Multiple Repositories ............................................... 229 8.5.26 Using Proxies ........................................................... 231 8.5.26 Using the Release Plugin ................................................. 232 8.5.26 Using Ant with Maven .................................................... 237 8.5.26 Using Modello ........................................................... 239 8.5.26 Webapps ............................................................... 243 8.5.26 Using Extensions ........................................................ 244 8.5.26 Building For Different Environments with Maven 2 ............................ 245 8.5.26 Using Toolchains ........................................................ 248 8.5.26 Encrypting passwords in settings.xml ....................................... 251 8.5.26 Reusable Test JARs ..................................................... 254 8.6 Eclipse Integration ........................................................... 256 8.7 Netbeans Integration ......................................................... 257 9 Plugin Developer Centre ................................................. 258 9.1 Testing your Plugin .......................................................... 259 9.2 Documenting your Plugin ..................................................... 268 9.3 Common Bugs and Pitfalls ................................................... 269 9.4 Mojo API .................................................................... 277 10 Maven Repository Centre ................................................ 291 10.1 Guide to Maven Evangelism .................................................. 293 10.2 Guide to uploading artifacts .................................................. 294 11 Maven Developer Centre ................................................. 297 11.1 Developing Maven 2 ......................................................... 299 11.2 Building Maven 2 ............................................................ 302 11.3 Committer Environment ...................................................... 305 11.4 Committer Settings ........................................................... 307 11.5 Maven Code Style And Conventions .......................................... 309 11.6 Maven JIRA Convention ..................................................... 313 ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. Table of Contents iii 11.7 Maven SVN Convention ...................................................... 315 11.8 Making GPG Keys ........................................................... 317 11.9 Release Process ............................................................. 320 11.10 Deploy Maven Current References ........................................... 321 12 External Resources ....................................................... 322 13 Project Reports ........................................................... 327 13.1 Continuous Integration ....................................................... 328 13.2 Project License .............................................................. 329 13.3 Mailing Lists ................................................................. 333 13.4 Project Team ................................................................ 334 ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. Table of Contents iv ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. 1 What is Maven? 1 1 What is Maven? ....................................................................................................................................... 1.1 Introduction Maven, a Yiddish word meaning accumulator of knowledge, was originally started as an attempt to simplify the build processes in the Jakarta Turbine project. There were several projects each with their own Ant build files that were all slightly different and JARs were checked into CVS. We wanted a standard way to build the projects, a clear definition of what the project consisted of, an easy way to publish project information and a way to share JARs across several projects. The result is a tool that can now be used for building and managing any Java-based project. We hope that we have created something that will make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project. 1.2 Maven's Objectives Maven's primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with: • Making the build process easy • Providing a uniform build system • Providing quality project information • Providing guidelines for best practices development • Allowing transparent migration to new features 1.2.1 Making the build process easy While using Maven doesn't eliminate the need to know about the underlying mechanisms, Maven does provide a lot of shielding from the details. 1.2.2 Providing a uniform build system Maven allows a project to build using its project object model (POM) and a set of plugins that are shared by all projects using Maven, providing a uniform build system. Once you familiarize yourself with how one Maven project builds you automatically know how all Maven projects build saving you immense amounts of time when trying to navigate many projects. 1.2.3 Providing quality project information Maven provides plenty of useful project information that is in part taken from your POM and in part generated from your project's sources. For example, Maven can provide: • Change log document created directly from source control • Cross referenced sources • Mailing lists • Dependency list • Unit test reports including coverage As Maven improves the information set provided will improve, all of which will be transparent to users of Maven. Other products can also provide Maven plugins to allow their set of project information alongside some of the standard information given by Maven, all still based on the POM. ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. 1 What is Maven? 2 1.2.4 Providing guidelines for best practices development Maven aims to gather current principles for best practices development, and make it easy to guide a project in that direction. For example, specification, execution, and reporting of unit tests are part of the normal build cycle using Maven. Current unit testing best practices were used as guidelines: • Keeping your test source code in a separate, but parallel source tree • Using test case naming conventions to locate and execute tests • Have test cases setup their environment and don't rely on customizing the build for test preparation. Maven also aims to assist in project workflow such as release management and issue tracking. Maven also suggests some guidelines on how to layout your project's directory structure so that once you learn the layout you can easily navigate any other project that uses Maven and the same defaults. 1.2.5 Allowing transparent migration to new features Maven provides an easy way for Maven clients to update their installations so that they can take advantage of any changes that been made to Maven itself. Installation of new or updated plugins from third parties or Maven itself has been made trivial for this reason. 1.3 What is Maven Not? You may have heard some of the following things about Maven: • Maven is a site and documentation tool • Maven extends Ant to let you download dependencies • Maven is a set of reusable Ant scriptlets While Maven does these things, as you can read above in the "What is Maven?" section, these are not the only features Maven has, and its objectives are quite different. Maven does encourage best practices, but we realise that some projects may not fit with these ideals for historical reasons. While Maven is designed to be flexible, to an extent, in these situations and to the needs of different projects, it can not cater to every situation without making compromises to the integrity of its objectives. If you decide to use Maven, and have an unusual build structure that you cannot reorganise, you may have to forgo some features or the use of Maven altogether. ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. 2 Features 3 2 Features ....................................................................................................................................... 2.1 Feature Summary The following are the key features of Maven in a nutshell: • Simple project setup that follows best practices - get a new project or module started in seconds • Consistent usage across all projects means no ramp up time for new developers coming onto a project • Superior dependency management including automatic updating, dependency closures (also known as transitive dependencies) • Able to easily work with multiple projects at the same time • A large and growing repository of libraries and metadata to use out of the box, and arrangements in place with the largest Open Source projects for real-time availability of their latest releases • Extensible, with the ability to easily write plugins in Java or scripting languages • Instant access to new features with little or no extra configuration • Ant tasks for dependency management and deployment outside of Maven • Model based builds: Maven is able to build any number of projects into predefined output types such as a JAR, WAR, or distribution based on metadata about the project, without the need to do any scripting in most cases. • Coherent site of project information: Using the same metadata as for the build process, Maven is able to generate a web site or PDF including any documentation you care to add, and adds to that standard reports about the state of development of the project. Examples of this information can be seen at the bottom of the left-hand navigation of this site under the "Project Information" and "Project Reports" submenus. • Release management and distribution publication: Without much additional configuration, Maven will integrate with your source control system such as CVS and manage the release of a project based on a certain tag. It can also publish this to a distribution location for use by other projects. Maven is able to publish individual outputs such as a JAR, an archive including other dependencies and documentation, or as a source distribution. • Dependency management: Maven encourages the use of a central repository of JARs and other dependencies. Maven comes with a mechanism that your project's clients can use to download any JARs required for building your project from a central JAR repository much like Perl's CPAN. This allows users of Maven to reuse JARs across projects and encourages communication between projects to ensure that backward compatibility issues are dealt with. We are collaborating with the folks at Ibiblio who have graciously allowed the central repository to live on their servers. ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED. 3 FAQ 4 3 FAQ ....................................................................................................................................... 3.1 Frequently Asked Technical Questions 1 How do I prevent "[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!" 2 How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope! 3 How do I list available plugins? 4 How do I determine what version of a plugin I am using? 5 How can I use Ant tasks in a Maven build? 6 How can I use Maven features in an Ant build? 7 How do I set up Maven so it will compile with a target and source JVM of my choice? 8 Is it possible to create my own directory structure? 9 Where is the source code? I couldn't seem to find a link anywhere on the Maven2 site. 10Maven can't seem to download the dependencies. Is my installation correct? 11I have a jar that I want to put into my local repository. How can I copy it in? 12How do I unsubscribe from Maven mailing lists? 13How do I skip the tests? 14How can I run a single unit test? 15Handle special characters in site 16How do I include tools.jar in my dependencies? 17Maven compiles my test classes but doesn't run them? 18Where are Maven SNAPSHOT artifacts? 19Where are the Maven XSD schemas? 20Maven doesn't work, how do I get help? 21How to produce execution debug output or error messages? 22What is a Mojo? 23How to find dependencies on public Maven repositories? How do I prevent "[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!" This or a similar warning is emitted by a plugin that processes plain text files but has not been configured to use a specific file encoding. So eliminating the warning is simply a matter of finding out what plugin emits it and how to configure the file encoding for it. For plugins that follow our guideline for source file encoding, this is as easy as adding the following property to your POM (or one of its parent POMs): <project> ... <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> ... </project> [top] ©2011, The Apache Software Foundation • ALL RIGHTS RESERVED.

Description:
8.5.8 Configuring Plug-ins . 9.1.1 CI Servers. Following is an alphabetical list of some CI servers we've heard mentioned around the Maven community: • Apache Continuum. • Bamboo ..
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.