Jump to content

Gradle

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 73.12.22.63 (talk) at 22:58, 10 August 2020 (6.6 is out). 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, Luke Daley, Rene Gröschke, Daz DeBoer
Initial release2007; 17 years ago (2007)
Stable release
6.6 / August 10, 2020; 4 years ago (2020-08-10)[1]
Preview release
6.6 RC6 / August 5, 2020; 4 years ago (2020-08-05)
Repository
Written inJava, Groovy, Kotlin
TypeBuild tool
LicenseApache License 2.0
Websitewww.gradle.org

Gradle is a build automation tool for multi-language software development. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing.

The methodology of Gradle builds on the concepts of Apache Ant and Apache Maven, and introduces a Groovy-based domain-specific language, rather than using the XML form used by Maven for declaring the project configuration.[2] 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. It produces web-based build visualization. The software is extensible for new features and programming languages with a plugin subsystem.

Gradle is distributed as open-source software under the Apache License 2.0, and was first release in 2007.

History

As of 2016 the initial plugins were primarily focused on Java,[3] Groovy and Scala development and deployment.

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.

File build.gradle

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.

File build.gradle

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.

File build.xml

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

File build.gradle

ant.importBuild 'build.xml'

Running the command gradle ant.target results in

> gradle ant.target
:ant.target
[ant:echo] Running ant.target!

BUILD SUCCESSFUL

See also

References

  1. ^ "Gradle Distributions". Gradle Services.
  2. ^ "Getting Started With Gradle". Petri Kainulainen. Retrieved 26 March 2016.
  3. ^ "Getting Started · Building Java Projects with Gradle". Retrieved 26 March 2016.

Bibliography