allprojects { }
artifacts { }
buildscript { }
configurations { }
dependencies { }
repositories { }
sourceSets { }
subprojects { }
publishing { }
Project
Task
Gradle
Settings
Script
SourceSet
SourceSetOutput
IncrementalTaskInputs
Configuration
ResolutionStrategy
ConventionProperty
ExtensionAware
ExtraPropertiesExtension
PublishingExtension
IvyPublication
IvyArtifact
IvyArtifactSet
IvyModuleDescriptor
MavenPublication
MavenArtifact
MavenArtifactSet
MavenPom
ConfigurationContainer
RepositoryHandler
DependencyHandler
ArtifactHandler
TaskReportTask
ProjectReportTask
DependencyReportTask
DependencyInsightReportTask
PropertyReportTask
AntlrTask
Checkstyle
CodeNarc
CompareGradleBuilds
Copy
CreateStartScripts
Delete
Directory
Ear
Exec
FindBugs
GenerateIvyDescriptor
GenerateMavenPom
GenerateBuildDashboard
GradleBuild
GroovyCompile
Groovydoc
JacocoReport
JacocoMerge
Jar
JavaCompile
Javadoc
JavaExec
JDepend
JettyRun
JettyRunWar
JettyStop
Pmd
PublishToIvyRepository
PublishToMavenRepository
ScalaCompile
ScalaDoc
Sign
SonarAnalyze
Sync
Tar
Test
TestReport
Upload
War
Wrapper
Zip
EclipseModel
EclipseProject
EclipseClasspath
EclipseJdt
EclipseWtp
EclipseWtpComponent
EclipseWtpFacet
IdeaModel
IdeaProject
IdeaModule
IdeaWorkspace
XmlFileContentMerger
FileContentMerger
GenerateEclipseProject
GenerateEclipseClasspath
GenerateEclipseJdt
GenerateEclipseWtpComponent
GenerateEclipseWtpFacet
GenerateIdeaModule
GenerateIdeaProject
GenerateIdeaWorkspace
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 areconfiguration 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 typeProject
. This object is called thedelegate 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 theScript
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 aconfiguration closure which configures some delegate object as it executes. The top level script blocks are listed below.
Block | Description |
allprojects { } | Configures this project and each of its sub-projects. |
artifacts { } | Configures the published artifacts for this project. |
buildscript { } | Configures the build script classpath for this project. |
configurations { } | Configures the dependency configurations for this project. |
dependencies { } | Configures the dependencies for this project. |
repositories { } | Configures the repositories for this project. |
sourceSets { } | Configures the source sets of this project. |
subprojects { } | Configures the sub-projects of this project. |
publishing { } | Configures the |
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:
Type | Description |
Project | This interface is the main API you use to interact with Gradle from your build file. From a |
Task | A |
Gradle | Represents an invocation of Gradle. |
Settings | Declares the configuration required to instantiate and configure the hierarchy of |
Script | This interface is implemented by all Gradle scripts to add in some Gradle-specific methods. As your compiledscript class will implement this interface, you can use the methods and properties declared by this interfacedirectly in your script. |
SourceSet | A |
SourceSetOutput | A collection of all output directories (compiled classes, processed resources, etc.) - notice that |
IncrementalTaskInputs | Provides access to any input files that need to be processed by an incremental task. |
Configuration | A |
ResolutionStrategy | Defines the strategies around dependency resolution.For example, forcing certain dependency versions, conflict resolutions or snapshot timeouts. |
ConventionProperty | ConventionProperty can be assigned butcannot be mutated (even if the object is mutable!) |
ExtensionAware | Objects that can be extended at runtime with other objects. |
ExtraPropertiesExtension | Additional, ad-hoc, properties for Gradle domain objects. |
PublishingExtension | The configuration of how to “publish” the different components of a project. |
IvyPublication | A |
IvyArtifact | An artifact published as part of a |
IvyArtifactSet | A Collection of |
IvyModuleDescriptor | The descriptor of any Ivy publication. |
MavenPublication | A |
MavenArtifact | An artifact published as part of a |
MavenArtifactSet | A Collection of |
MavenPom | The POM for a Maven publication.The |
Container types that handle various declarative elements (e.g. dependencies, configurations, artifacts, etc.):
Type | Description |
ConfigurationContainer | A |
RepositoryHandler | A |
DependencyHandler | A |
ArtifactHandler | This class is for defining artifacts to be published and adding them to configurations. Creating publish artifactsdoes not mean to create an archive. What is created is a domain object which represents a file to be publishedand information on how it should be published (e.g. the name). |
Below are the task types that are available for every Gradle project. Those task types can also be declared and configured directly in the build script.
Type | Description |
TaskReportTask | Displays a list of tasks in the project. An instance of this type is used when you execute the |
ProjectReportTask | Displays a list of projects in the build. An instance of this type is used when you execute the |
DependencyReportTask | Displays the dependency tree for a project. An instance of this type is used when youexecute the |
DependencyInsightReportTask | Generates a report that attempts to answer questions like: |
PropertyReportTask | Displays the properties of a project. An instance of this type is used when you execute the |
Listed below are the various task types which are available for use in your build script:
Type | Description |
AntlrTask | Generates parsers from Antlr grammars. |
Checkstyle | Runs Checkstyle against some source files. |
CodeNarc | Runs CodeNarc against some source files. |
CompareGradleBuilds | Executes two Gradle builds (that can be the same build) with specified versions and compares the outcomes.Please see the “Comparing Builds” chapter of the Gradle User Guide for more information. |
Copy | Copies files into a destination directory. This task can also rename and filter files as it copies. The taskimplements |
CreateStartScripts | A |
Delete | Deletes files or directories. Example: |
Directory | Creates a directory. |
Ear | Assembles an EAR archive. |
Exec | Executes a command line process. Example: |
FindBugs | Analyzes code withFindBugs. See theFindBugs Manual for additional informationon configuration options. |
GenerateIvyDescriptor | Generates an Ivy XML Module Descriptor file. |
GenerateMavenPom | Generates an Ivy XML Module Descriptor file. |
GenerateBuildDashboard | Generates build dashboard report. |
GradleBuild | Executes a Gradle build. |
GroovyCompile | Compiles Groovy source files, and optionally, Java source files. |
Groovydoc | Generates HTML API documentation for Groovy source, and optionally, Java source. |
JacocoReport | Task to generate HTML, Xml and CSV reports of Jacoco coverage data. |
JacocoMerge | Task to merge multiple execution data files into one. |
Jar | Assembles a JAR archive. |
JavaCompile | Compiles Java source files. |
Javadoc | Generates HTML API documentation for Java classes. |
JavaExec | Executes a Java application in a child process. |
JDepend | Analyzes code withJDepend. |
JettyRun | Deploys an exploded web application to an embedded Jetty web container. Does not require that the web applicationbe assembled into a war, saving time during the development cycle. |
JettyRunWar | Deploys a WAR to an embedded Jetty web container. |
JettyStop | Stops the embedded Jetty web container, if it is running. |
Pmd | Runs a set of static code analysis rules on Java source code files andgenerates a report of problems found. |
PublishToIvyRepository | Publishes an IvyPublication to an IvyArtifactRepository. |
PublishToMavenRepository | Publishes a |
ScalaCompile | Compiles Scala source files, and optionally, Java source files. |
ScalaDoc | Generates HTML API documentation for Scala source files. |
Sign | A task for creating digital signature files for one or more; tasks, files, publishable artifacts or configurations. |
SonarAnalyze | Analyzes a project hierarchy and writes the results to theSonar database. |
Sync | Synchronises the contents of a destination directory with some source directories and files. |
Tar | Assembles a TAR archive. |
Test | Executes JUnit (3.8.x or 4.x) or TestNG tests. Test are always run in (one or more) separate JVMs.The sample below shows various configuration options. |
TestReport | Generates an HTML test report from the results of one or more |
Upload | Uploads the artifacts of a |
War | Assembles a WAR archive. |
Wrapper | Generates scripts (for *nix and windows) which allow you to build your project with Gradle, without having toinstall Gradle. |
Zip | Assembles a ZIP archive.The default is to compress the contents of the zip. |
Used to configure Eclipse or IDEA plugins
Type | Description |
EclipseModel | DSL-friendly model of the Eclipse project information.First point of entry for customizing Eclipse project generation. |
EclipseProject | Enables fine-tuning project details (.project file) of the Eclipse plugin |
EclipseClasspath | The build path settings for the generated Eclipse project. Used by the |
EclipseJdt | Enables fine-tuning jdt details of the Eclipse plugin |
EclipseWtp | Enables fine-tuning wtp/wst details of the Eclipse plugin |
EclipseWtpComponent | Enables fine-tuning wtp component details of the Eclipse plugin |
EclipseWtpFacet | Enables fine-tuning wtp facet details of the Eclipse plugin |
IdeaModel | DSL-friendly model of the IDEA project information.First point of entry when it comes to customizing the IDEA generation. |
IdeaProject | Enables fine-tuning project details (*.ipr file) of the IDEA plugin. |
IdeaModule | Enables fine-tuning module details (*.iml file) of the IDEA plugin . |
IdeaWorkspace | Enables fine-tuning workspace details (*.iws file) of the IDEA plugin. |
XmlFileContentMerger | Models the generation/parsing/merging capabilities. Adds XML-related hooks. |
FileContentMerger | Models the generation/parsing/merging capabilities. |
Tasks contributed by IDE plugins. To configure IDE plugins please use IDE model types.
Type | Description |
GenerateEclipseProject | Generates an Eclipse |
GenerateEclipseClasspath | Generates an Eclipse |
GenerateEclipseJdt | Generates the Eclipse JDT configuration file. If you want to fine tune the eclipse configuration |
GenerateEclipseWtpComponent | Generates the org.eclipse.wst.common.component settings file for Eclipse WTP.If you want to fine tune the eclipse configuration |
GenerateEclipseWtpFacet | Generates the org.eclipse.wst.common.project.facet.core settings file for Eclipse WTP.If you want to fine tune the eclipse configuration |
GenerateIdeaModule | Generates an IDEA module file. If you want to fine tune the idea configuration |
GenerateIdeaProject | Generates an IDEA project file for root project *only*. If you want to fine tune the idea configuration |
GenerateIdeaWorkspace | Generates an IDEA workspace file *only* for root project.There's little you can configure about workspace generation at the moment. |