This article needs to be updated.June 2020)(
|Developer(s)||Hans Dockter, Adam Murdoch, Szczepan Faber, Peter Niederwieser, Luke Daley, Rene Gröschke, Daz DeBoer|
6.8.3 / 22 February 2021
6.8 RC5 / 4 January 2021
|Written in||Java, Groovy, Kotlin|
|License||Apache License 2.0|
Gradle builds on the concepts of Apache Ant and Apache Maven, and introduces a Groovy- & Kotlin-based domain-specific language contrasted with the XML-based project configuration used by Maven. Gradle uses a directed acyclic graph to determine the order in which tasks can be run, through providing dependency management.
Gradle was designed for multi-project builds, which can grow to be large. It operates based on a series of build tasks that can run serially or in parallel. Incremental builds are supported by determining the parts of the build tree that are already up to date; any task dependent only on those parts does not need to be re-executed. It also supports caching of build components, potentially across a shared network using the Gradle Build Cache. It produces web-based build visualization called Gradle Build Scans. The software is extensible for new features and programming languages with a plugin subsystem.
Example Java project
In this example, 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.
apply plugin: 'java'
Running the build task (gradle build) results in the console log:
> 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.
apply plugin: 'java' sourceSets.main.java.srcDirs = ['src/java']
Example Ant migration
Gradle is tightly integrated with Ant, and even treats Ant build files as scripts that could be directly imported while building. This example shows a simplistic Ant target being incorporated as a Gradle task.
<project> <target name="ant.target"> <echo message="Running ant.target!"/> </target> </project>
Running the command gradle ant.target results in
> gradle ant.target :ant.target [ant:echo] Running ant.target! BUILD SUCCESSFUL
- "Gradle Distributions". Gradle Services.
- "Gradle User Manual". docs.gradle.org. Retrieved 14 November 2020.
- "Getting Started With Gradle". Petri Kainulainen. Retrieved 26 March 2016.
- "Getting Started · Building Java Projects with Gradle". Retrieved 26 March 2016.
- Berglund, Tim; McCullough, Matthew (July 2011). Building and Testing with Gradle. Foreword by Hans Dockter (First ed.). O'Reilly Media. p. 116. ISBN 978-1-4493-0463-8.
- Berglund, Tim (August 2013). Gradle Beyond the Basics (First ed.). O'Reilly Media. p. 69. ISBN 978-1-449-30467-6.
- Ikkink, Hubert (November 2012). Gradle Effective Implementation Guide (First ed.). Packt Publishing. p. 382. ISBN 978-1849518109.
- Berglund, Tim; McCullough, Matthew (May 2013). Gradle DSLs (First ed.). O'Reilly Media. pp. 50 est. ISBN 978-1-4493-0467-6.
- Muschko, Benjamin (Fall 2013). Gradle in Action (First ed.). Manning Publications. p. 390. ISBN 9781617291302.