Gradle
Encyclopedia
Gradle is a project automation tool that builds upon the concepts of Apache Ant
and Apache Maven
and introduces a Groovy based DSL instead of the more traditional XML
form of declaring the project configuration.
Unlike Apache Maven
, which defines lifecycles, and Apache Ant
, where targets are invoked based upon a depends-on partial ordering, Gradle utilizes a directed acyclic graph
("DAG") to determine the order in which tasks can be run.
Gradle was designed for multi-project builds which can grow to be quite large, and as such, it supports incremental builds by intelligently determining which parts of the build tree are up-to-date, so that any task dependent upon those parts will not need to be re-executed.
The initial plugins are primarily focused around Java
, Groovy and Scala development and deployment, but more languages and project workflows are on the roadmap.
directory structure is used for Java sources and resources. These directories are: src/main/java, src/main/resources, src/test/java and src/test/resources.
build.gradle
apply plugin: 'java'
Running gradle build will result in
> gradle build
BUILD SUCCESSFUL
The Java plugin emulates many of the expected Maven lifecycles as tasks in the directed acyclic graph of dependencies for the inputs and outputs of each task. For this simple case, the build task depends upon the outputs of the check and assemble tasks. Likewise, check depends upon test, and assemble depends upon jar.
For projects that do not follow the Maven conventions, Gradle allows the directory structure to be configured. The following example would support a project that contains source files in src/java rather than the src/main/java convention enforced by Maven.
build.gradle
apply plugin: 'java'
sourceSets.main.java.srcDirs = ['src/java']
build.xml
build.gradle
ant.importBuild 'build.xml'
Running gradle ant.target will result in
> gradle ant.target
[ant:echo] Running ant.target!
BUILD SUCCESSFUL
Apache Ant
Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects....
and Apache Maven
Apache Maven
Maven is a build automation and software comprehension tool. While primarily used for Java programming, it can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Maven serves a similar purpose to the Apache Ant tool, but it is based on different concepts and...
and introduces a Groovy based DSL instead of the more traditional XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
form of declaring the project configuration.
Unlike Apache Maven
Apache Maven
Maven is a build automation and software comprehension tool. While primarily used for Java programming, it can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Maven serves a similar purpose to the Apache Ant tool, but it is based on different concepts and...
, which defines lifecycles, and Apache Ant
Apache Ant
Apache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects....
, where targets are invoked based upon a depends-on partial ordering, Gradle utilizes a directed acyclic graph
Directed acyclic graph
In mathematics and computer science, a directed acyclic graph , is a directed graph with no directed cycles. That is, it is formed by a collection of vertices and directed edges, each edge connecting one vertex to another, such that there is no way to start at some vertex v and follow a sequence of...
("DAG") to determine the order in which tasks can be run.
Gradle was designed for multi-project builds which can grow to be quite large, and as such, it supports incremental builds by intelligently determining which parts of the build tree are up-to-date, so that any task dependent upon those parts will not need to be re-executed.
The initial plugins are primarily focused around Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, Groovy and Scala development and deployment, but more languages and project workflows are on the roadmap.
Example Java Project
Consider the case where the MavenApache Maven
Maven is a build automation and software comprehension tool. While primarily used for Java programming, it can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Maven serves a similar purpose to the Apache Ant tool, but it is based on different concepts and...
directory structure is used for Java sources and resources. These directories are: src/main/java, src/main/resources, src/test/java and src/test/resources.
build.gradle
apply plugin: 'java'
Running gradle build will result in
> gradle build
- compileJava
- processResources
- classes
- jar
- assemble
- compileTestJava
- processTestResources
- testClasses
- test
- check
- build
BUILD SUCCESSFUL
The Java plugin emulates many of the expected Maven lifecycles as tasks in the directed acyclic graph of dependencies for the inputs and outputs of each task. For this simple case, the build task depends upon the outputs of the check and assemble tasks. Likewise, check depends upon test, and assemble depends upon jar.
For projects that do not follow the Maven conventions, Gradle allows the directory structure to be configured. The following example would support a project that contains source files in src/java rather than the src/main/java convention enforced by Maven.
build.gradle
apply plugin: 'java'
sourceSets.main.java.srcDirs = ['src/java']
Example Ant Migration
Gradle has a very tight integration with Ant, and even treats Ant build files as first class citizens. The below example shows a simplistic Ant target being incorporated as a Gradle task.build.xml
build.gradle
ant.importBuild 'build.xml'
Running gradle ant.target will result in
> gradle ant.target
- ant.target
[ant:echo] Running ant.target!
BUILD SUCCESSFUL
See also
- Apache AntApache AntApache Ant is a software tool for automating software build processes. It is similar to Make but is implemented using the Java language, requires the Java platform, and is best suited to building Java projects....
- Apache MavenApache MavenMaven is a build automation and software comprehension tool. While primarily used for Java programming, it can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. Maven serves a similar purpose to the Apache Ant tool, but it is based on different concepts and...
- Apache BuildrApache BuildrBuildr is an open-source build system mainly intended to build Java applications, but capable of doing much more. It gives the developer the power of a full-blown scripting language while writing his or her build scripts, much missed in XML-based building environments like Apache Ant or Apache...
- Make
- RakeRake (software)Rake is a software task management tool. It allows you to specify tasks and describe dependencies as well as to group tasks in a namespace.It is similar to SCons and make, but has a number of differences. The tool is written in the Ruby programming language, and the Rakefiles use Ruby syntax...
- SConsSConsSCons is a computer software construction tool that automatically analyzes source code file dependencies and operating system adaptation requirements from a software project description and generates final binary executables for installation on the target operating system platform...
External links
- gradle.org
- gradleware.com for commercial Gradle support
- Overview of Gradle
- Standard plugins that ship with Gradle
- Gradle: Java Quickstart Guide
- Gradle: Groovy Quickstart Guide
- Examples of Ant usage within Gradle
- Gradle Forums
- Gradle Presentation
- Abuild, another DAGDirected acyclic graphIn mathematics and computer science, a directed acyclic graph , is a directed graph with no directed cycles. That is, it is formed by a collection of vertices and directed edges, each edge connecting one vertex to another, such that there is no way to start at some vertex v and follow a sequence of...
based build tool