You are previewing Apache Maven Cookbook.
O'Reilly logo
Apache Maven Cookbook

Book Description

Over 90 hands-on recipes to successfully build and automate development life cycle tasks following Maven conventions and best practices

In Detail

Apache Maven offers a comprehensive set of features to build, test, release, and deploy software projects and maintain enterprise development infrastructure.

This book is a hands-on guide that enables you to explore the vast potential of Apache Maven, the leading software build tool. You will start off by successfully installing Apache Maven on your favorite OS, and then you will create your first working project. Furthermore, the book walks you through setting up and using Maven with popular Java Integrated Development Environments (IDEs) so you can exploit Maven features to build standard Java applications. Above all, you will also learn to create site reports and documentation for your project along with handling typical build requirements and other advanced Maven usages.

What You Will Learn

  • Install Apache Maven successfully on your preferred OS

  • Explore the various features of Apache Maven to build efficient automation tools

  • Discover when and how to use the various Apache Maven plugins

  • Generate and publish your project documentation using Apache Maven

  • Analyze and control code quality and code coverage using Apache Maven

  • Build various types of Java projects as well as other binaries

  • Set up complex projects using the concept of inheritance

  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. 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.

    Table of Contents

    1. Apache Maven Cookbook
      1. Table of Contents
      2. Apache Maven Cookbook
      3. Credits
      4. About the Author
      5. About the Reviewers
      6. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Sections
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
          5. See also
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book
          3. Errata
          4. Piracy
          5. Questions
      8. 1. Getting Started
        1. Introduction
          1. A brief comparison with other build automation tools
        2. Installing Maven on Microsoft Windows
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Installing Maven on Mac OS X
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Installing Maven on Linux
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Changing the JDK used by Maven
          1. How to do it...
          2. How it works...
        6. Creating a simple project with Maven
          1. How to do it...
          2. How it works...
          3. See also
        7. Building a simple project with Maven
          1. How to do it...
          2. How it works...
        8. Changing the location of the Maven repository
          1. How to do it...
          2. How it works...
        9. Running Maven behind an HTTP proxy server
          1. How to do it...
          2. How it works...
        10. Understanding the standard directory layout
          1. How to do it...
          2. How it works...
      9. 2. IDE Integration with Maven
        1. Introduction
        2. Creating a new Maven project in Eclipse
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Importing an existing Maven project in Eclipse
          1. How to do it...
          2. How it works...
        4. Creating a new Maven project in NetBeans
          1. Getting ready
          2. How to do it...
          3. How it works...
        5. Importing an existing Maven project in NetBeans
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Creating a new Maven project in IntelliJ IDEA
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Importing an existing Maven project in IntelliJ IDEA
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      10. 3. Maven Lifecycle
        1. Introduction
        2. Understanding the Maven lifecycle, phases, and goals
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Understanding the pom file
          1. How to do it...
          2. How it works...
        4. Understanding Maven settings
          1. How to do it...
          2. How it works...
            1. The localRepository element
            2. The offline element
            3. The proxies element
            4. The mirrors element
            5. The repositories element
            6. The pluginRepositories element
            7. The servers element
        5. Understanding command-line options in Maven
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Options
        6. Understanding Maven profiles
          1. How to do it...
          2. How it works...
        7. Adding a new Maven profile
          1. How to do it...
          2. How it works...
          3. See also
        8. Activating/deactivating a Maven profile
          1. Getting ready
          2. How to do it...
          3. How it works...
        9. Using properties in Maven
          1. How to do it...
          2. How it works...
          3. See also
        10. Specifying source encoding for platform-independent builds
          1. How to do it...
          2. How it works...
      11. 4. Essential Maven Plugins
        1. Introduction
        2. Using the Maven Clean plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Cleaning automatically
            2. Skipping the deletion of the working directory
            3. Deleting additional folders/files
        3. Using the Maven Compiler plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Changing the compiler used by the Maven Compiler plugin
          1. How to do it...
          2. How it works...
          3. See also
        5. Specifying the Java version for the Compiler plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Using the Maven Surefire plugin to run unit tests
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Using TestNG
            2. Skipping tests
            3. Skipping the compilation of test sources
        7. Using the Maven Failsafe plugin to run integration tests
          1. How to do it...
          2. How it works...
        8. Using the Maven Resources plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        9. Filtering using resources
          1. How to do it...
          2. How it works...
          3. There's more...
        10. Using Eclipse to run Maven goals
          1. How to do it...
          2. How it works...
        11. Using NetBeans to run Maven goals
          1. How to do it...
          2. How it works...
        12. Using IntelliJ IDEA to run Maven goals
          1. How to do it...
          2. How it works...
      12. 5. Dependency Management
        1. Introduction
        2. Choosing the scope of dependency
          1. How to do it...
          2. How it works...
          3. See also
        3. Getting a report of dependencies
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        4. Getting into dependency and avoiding dependency hell
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        5. Downloading dependencies into a folder
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Understanding SNAPSHOT dependencies
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Handling dependency download errors
          1. How to do it...
          2. How it works...
        8. Detecting unused/undeclared dependencies
          1. How to do it...
          2. How it works...
        9. Manually installing dependencies that are not available in a repository
          1. How to do it...
          2. How it works...
          3. There's more...
        10. Dependency management using Eclipse
          1. How to do it...
          2. How it works...
          3. There's more...
        11. Dependency management using NetBeans
          1. How to do it...
          2. How it works...
        12. Dependency management using IntelliJ IDEA
          1. How to do it...
          2. How it works...
      13. 6. Code Quality Plugins
        1. Introduction
        2. Analyzing code coverage with the Maven JaCoCo plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Analyzing code coverage with the Maven Cobertura plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Analyzing code with the Maven PMD plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Analyzing code with the Maven Checkstyle plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Analyzing code with the Maven FindBugs plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Generating source references with the Maven JXR plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Analyzing code with the Maven SonarQube plugin
          1. Getting ready...
          2. How to do it...
          3. How it works...
          4. There's more...
      14. 7. Reporting and Documentation
        1. Introduction
        2. Documenting with the Maven Site plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Generating Javadocs for a site
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Generating source cross-reference for a site
          1. How to do it...
          2. How it works...
        5. Generating unit test reports for a site
          1. How to do it...
          2. How it works...
        6. Generating code coverage reports for a site
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Generating code quality reports for a site
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Generating selective reports
          1. How to do it...
          2. How it works...
        9. Deploying a site
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      15. 8. Handling Typical Build Requirements
        1. Introduction
        2. Including and excluding additional resources
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Including and excluding source files and folders
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Configuring Maven to search for plugins
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Working in offline mode
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Controlling the verbosity of the Maven output
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Using the Maven Help plugin
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Using the Maven SCM plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        9. Generating changelogs for a site
          1. How to do it...
          2. How it works...
      16. 9. Multi-module Projects
        1. Introduction
        2. Understanding project inheritance
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        3. Understanding project aggregation
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Combining inheritance and aggregation
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Performing multi-module dependency management
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Performing multi-module plugin management
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Selectively building modules
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Reporting for multi-module projects
          1. How to do it...
          2. How it works...
          3. There's more...
      17. 10. Java Development with Maven
        1. Introduction
        2. Building a JAR project
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        3. Generating an executable JAR
          1. How to do it...
          2. How it works...
        4. Generating a JAR of the source code
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Generating a JAR of the test classes
          1. How to do it...
          2. How it works...
        6. Building a WAR project
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Building an EAR project
          1. How to do it...
          2. How it works...
        8. Building a pom project
          1. How to do it...
          2. How it works...
          3. There's more...
        9. Running a web project with Jetty
          1. How to do it...
          2. How it works...
          3. There's more...
        10. Running a web project with Tomcat
          1. How to do it...
          2. How it works...
          3. There's more...
      18. 11. Advanced Maven Usage
        1. Introduction
        2. Creating an assembly
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Running a custom executable
          1. How to do it...
          2. How it works...
          3. There's more...
        4. Running an ANT task
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Determining updates to Maven plugin AntRun
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Determining updates to Maven dependencies
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Controlling the constraints
          1. How to do it...
          2. How it works...
          3. There's more...
        8. Generating unique builds
          1. How to do it...
          2. How it works...
        9. Releasing a Maven project
          1. How to do it...
          2. How it works...
      19. Index