Builds with Gradle, Buildr, Maven, and Ant

Java application deployment

Builds with Gradle, Buildr, Maven, and Ant

By Richard Mayhew

TheServerSide.com

Builds with Gradle, Buildr, Maven, and Ant

We’ll be looking at identical builds for three build tools: gradle, maven, and buildr. There are no differences between the project file structures, only the build directive files were different.

The “test project” was a simple Newton-Raphson implementation for calculating square roots, with one interface, one implementation (using 1.6’s “@Override” in the implementation), and one TestNG test; the goal is to show a simple project with a TestNG dependency. Other dependencies shouldn’t change the build files much.

Maven

This is our baseline project configuration, and should represent a close minimum of a Maven 3.0 pom for a project with a dependency on JDK 1.6 and TestNG. It will use the most recent version of TestNG that it is able to find (which is the “[5.14.0,)” version number in the TestNG dependency block.) The file will normally be named pom.xml:


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0

             http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

 

    <groupId>com.mayhewr</groupId>

    <artifactId>com.mayhewr.nr.maven</artifactId>

    <version>1.0</version>

    <dependencies>

        <dependency>

            <groupId>org.testng</groupId>

            <artifactId>testng</artifactId>

            <version>[5.14.1,)</version>

            <scope>test</scope>

        </dependency>

    </dependencies>

    <build>

        <plugins>

            <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-compiler-plugin</artifactId>

                <version>2.1</version>

                <configuration>

                    <source>1.6</source>

                    <target>1.6</target>

                </configuration>

            </plugin>

        </plugins>

    </build>

</project>


 

The project is built with “mvn package”. It gives a deployable artifact, called “com.mayhewr.nr.maven-1.0.jar” (the rest of these yield “nr-1.0.jar” files.)

Gradle

The equivalent gradle configuration file (build.gradle) would look like this:


apply plugin: 'java'

repositories {

    mavenCentral()

}

dependencies {

    testCompile group: 'org.testng', name: 'testng', version: '5.14+'

}

version='1.0'


The invocation command line is “gradle assemble”.

Buildr

Buildr’s build file is “buildfile”; the project definition looks like this:


repositories.remote << 'http://www.ibiblio.org/maven2'

define 'nr' do

   project.version='1.0'

   package :jar

   test.using :testng

   compile.using :source=>'1.6', :target=>'1.6'

end


The invocation command line is simply “buildr package”.

18 Nov 2010

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.