Book Image

Maven Build Customization

By : Lorenzo Anardu, Roberto Baldi, Umberto Antonio Cicero, Riccardo Giomi, Giacomo Veneri
Book Image

Maven Build Customization

By: Lorenzo Anardu, Roberto Baldi, Umberto Antonio Cicero, Riccardo Giomi, Giacomo Veneri

Overview of this book

<p>Maven is one of the most popular tools used to control the dependencies and to administer a Java project. Maven can be used by newbies without the need to learn complex mechanisms, but it is also a powerful tool for big projects developed by different teams and organized over different modules and repositories.</p> <p>This book will provide you with all the information you need, right from managing dependencies to improving the build process of your organization. Starting with a simple project, you will create your development environment step-by-step, automatically build your code from resources (XML, DB), and package your JAR, WAR, and EAR files for different environments. Furthermore, you will learn about the complex hereditary features of Maven.</p> <p>Finally, this book will benefit you by teaching Maven-Gradle and Maven-Eclipse integration using the m2e plugin, managing the Maven repository from Gradle, and building a working Maven environment from Gradle.</p>
Table of Contents (17 chapters)
Maven Build Customization
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating the project's POM


Gradle's Maven plugin can create a complete POM file. To make this operation possible, we can create an appropriate task:

task writeNewPom << {
  pom {
    project {
      inceptionYear '2014'
      licenses {
        license {
          name 'The Apache Software License, Version 2.0'
          url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
          distribution 'repo'
        }
      }
    }
  }.writeTo("$buildDir/pom.xml")
}

The pom object gives us all elements for the POM file, and we can override the default element inherited from the Gradle project configuration with other elements in order to customize POM creation. As the final instruction, perform a write of the POM file to the building directory with the name pom.xml using the following method:

.writeTo("$buildDir/pom.xml")

The resulting POM file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.gradle.test</groupId>
  <artifactId>gradle-project</artifactId>
  <version>1.0</version>
  <inceptionYear>2014</inceptionYear>
  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.+</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>commons-collections</groupId>
      <artifactId>commons-collections</artifactId>
      <version>3.2</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>