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>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset