Jump to content

Gradle

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 38.111.136.111 (talk) at 13:15, 10 April 2012 (External links). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Gradle
Developer(s)Hans Dockter, Adam Murdoch, Szczepan Faber, Peter Niederwieser, Ken Sipe
Stable release
1.0-milestone-9[1] / March 13, 2012 (2012-03-13)
Preview release
Gradle 1.0-rc-1[2] / March 13, 2012 (2012-03-13)
Repository
Written inJava, Groovy
Operating systemCross-platform
TypeBuild Tool
LicenseApache License 2.0
Websitehttp://www.gradle.org

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.

Example Java Project

Consider the case where the Maven 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

<project>
  <target name="ant.target">
    <echo message="Running ant.target!"/>
  </target>
</project>

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

References

See also

Bibliography

  • Berglund, Tim; McCullough, Matthew (July 2011). Building and Testing with Gradle. Foreword by Hans Dockter (First ed.). O'Reilly Media. p. 110. ISBN 978-1-4493-0463-8.
  • Berglund, Tim; McCullough, Matthew (April 2012 est.). Gradle DSLs (First ed.). O'Reilly Media. pp. 50 est. ISBN 978-1-4493-0467-6. {{cite book}}: Check date values in: |date= (help)