This reference guide describes the various types which make up the Gradle build language, or DSL.
There are a few basic concepts that you should understand, which will help you write Gradle scripts.
First, Gradle scripts are configuration scripts. As the script executes, it
configures an object of a particular type. For example, as a build script executes, it configures an
object of type
Project. This object is called the delegate object
of the script. The following table shows the delegate for each type of Gradle script.
The properties and methods of the delegate object are available for you to use in the script.
Second, each Gradle script implements the
Script interface. This
interface defines a number of properties and methods which you can use in the script.
A build script is made up of zero or more statements and script blocks. Statements can include method calls, property assignments, and local variable definitions. A script block is a method call which takes a closure as a parameter. The closure is treated as a configuration closure which configures some delegate object as it executes. The top level script blocks are listed below.
Configures this project and each of its sub-projects.
Configures the published artifacts for this project.
Configures the build script classpath for this project.
Configures the dependency configurations for this project.
Configures the dependencies for this project.
Configures the repositories for this project.
Configures the source sets of this project.
Configures the sub-projects of this project.
A build script is also a Groovy script, and so can contain those elements allowed in a Groovy script, such as method definitions and class definitions.
Listed below are some of the central types which are used in Gradle scripts:
This interface is the main API you use to interact with Gradle from your build file. From a
Represents an invocation of Gradle.
Declares the configuration required to instantiate and configure the hierarchy of
This interface is implemented by all Gradle scripts to add in some Gradle-specific methods. As your compiled script class will implement this interface, you can use the methods and properties declared by this interface directly in your script.
Defines the strategies around dependency resolution. For example, forcing certain dependency versions, conflict resolutions or snapshot timeouts.
ConventionProperty can be assigned but cannot be mutated (even if the object is mutable!)
Objects that can be extended at runtime with other objects.
Additional, ad-hoc, properties for Gradle domain objects.
Container types that handle various declarative elements (e.g. dependencies, configurations, artifacts, etc.):
This class is for defining artifacts to be published and adding them to configurations. Creating publish artifacts does not mean to create an archive. What is created is a domain object which represents a file to be published and information on how it should be published (e.g. the name).
Listed below are the various task types which are available for use in your build script:
Generates parsers from Antlr grammars.
Runs Checkstyle against some source files.
Runs CodeNarc against some source files.
Compiles Java source files.
Copies files into a destination directory. This task can also rename and filter files as it copies. The task
Deletes files or directories. Example:
Creates a directory.
Displays the dependency tree for a project. Can be configured to output to a file, and to optionally output a
graphviz compatible "dot" graph. An instance of this type is used when you execute the
Assembles an EAR archive.
Executes a command line process. Example:
Analyzes code with FindBugs.
Executes a Gradle build.
Compiles Groovy source files, and optionally, Java source files.
Generates HTML API documentation for Groovy source, and optionally, Java source.
Assembles a JAR archive.
Generates HTML API documentation for Java classes.
Executes a Java application in a child process.
Analyzes code with JDepend.
Deploys an exploded web application to an embedded Jetty web container. Does not require that the web application be assembled into a war, saving time during the development cycle.
Deploys a WAR to an embedded Jetty web container.
Stops the embedded Jetty web container, if it is running.
Runs a set of static code analysis rules on Java source code files and generates a report of problems found.
Displays the properties of a project. An instance of this type is used when you execute the
Displays a list of projects in the build. An instance of this type is used when you execute the
Compiles Scala source files, and optionally, Java source files.
Generates HTML API documentation for Scala source files.
A task for creating digital signature files for one or more; tasks, files, publishable artifacts or configurations.
Analyzes a project hierachy and writes the results to the Sonar database.
Synchronises the contents of a destination directory with some source directories and files.
Assembles a TAR archive.
Displays a list of tasks in the project. An instance of this type is used when you execute the
Executes tests. Supports JUnit (3.8.x or 4.x) or TestNG tests.
Uploads the artifacts of a
Assembles a WAR archive.
Generates scripts (for *nix and windows) which allow you to build your project with Gradle, without having to install Gradle.
Assembles a ZIP archive.
Used to configure Eclipse or IDEA plugins
DSL-friendly model of the Eclipse project information. First point of entry when it comes to customizing the eclipse generation
Enables fine-tuning project details (.project file) of the Eclipse plugin
Enables fine-tuning classpath details (.classpath file) of the Eclipse plugin
Enables fine-tuning jdt details of the Eclipse plugin
Enables fine-tuning wtp/wst details of the Eclipse plugin
Enables fine-tuning wtp component details of the Eclipse plugin
Enables fine-tuning wtp facet details of the Eclipse plugin
DSL-friendly model of the IDEA project information. First point of entry when it comes to customizing the IDEA generation.
Enables fine-tuning project details (*.ipr file) of the IDEA plugin.
Enables fine-tuning module details (*.iml file) of the IDEA plugin .
Enables fine-tuning workspace details (*.iws file) of the IDEA plugin.
Models the generation/parsing/merging capabilities. Adds xml-related hooks.
Models the generation/parsing/merging capabilities.
Tasks contributed by IDE plugins. To configure IDE plugins please use IDE model types.
Generates an Eclipse
Generates an Eclipse
Generates the Eclipse JDT configuration file. If you want to fine tune the eclipse configuration
Generates the org.eclipse.wst.common.component settings file for Eclipse WTP. If you want to fine tune the eclipse configuration
Generates the org.eclipse.wst.common.project.facet.core settings file for Eclipse WTP. If you want to fine tune the eclipse configuration
Generates an IDEA module file. If you want to fine tune the idea configuration
Generates an IDEA project file for root project *only*. If you want to fine tune the idea configuration
Generates an IDEA workspace file *only* for root project. There's little you can configure about workspace generation at the moment.