Movatterモバイル変換


[0]ホーム

URL:


Gradle Build Language Reference

Version 8.0.1

Introduction

This reference guide describes the various types which make up the Gradle build language, or DSL.

Some basics

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.

Type of scriptDelegates to instance of
Build scriptProject
Init scriptGradle
Settings scriptSettings

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.

Build script structure

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.

BlockDescription
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 thePublishingExtension added by the publishing plugin.

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.

Core types

Listed below are some of the central types which are used in Gradle scripts:

TypeDescription
Project

This interface is the main API you use to interact with Gradle from your build file. From aProject,you have programmatic access to all of Gradle's features.

Task

ATask represents a single atomic piece of work for a build, such as compiling classes or generatingjavadoc.

Gradle

Represents an invocation of Gradle.

Settings

Declares the configuration required to instantiate and configure the hierarchy ofProject instances which are to participate in a build.

IncludedBuild

A build that is included in the composite.

Script

This interface is implemented by all Gradle Groovy DSL 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

ASourceSet represents a logical group of Java source and resource files. Theyare covered in more detail in theuser manual.

SourceSetOutput

A collection of all output directories (compiled classes, processed resources, etc.) - notice thatSourceSetOutput extendsFileCollection.

SourceDirectorySet

ASourceDirectorySet represents a set of source files composed from a set of source directories, alongwith associated include and exclude patterns.

Configuration

AConfiguration represents a group of artifacts and their dependencies.Find more information about declaring dependencies to a configurationor about managing configurations in docs forConfigurationContainer

ResolutionStrategy

Defines the strategies around dependency resolution.For example, forcing certain dependency versions, substitutions, conflict resolutions or snapshot timeouts.

ArtifactResolutionQuery

A builder to construct a query that can resolve selected software artifacts of the specified components.

ComponentSelection

Represents a tuple of the component selector of a module and a candidate versionto be evaluated in a component selection rule.

ComponentSelectionRules

Represents a container for component selection rules. Rules can be applied as part of theresolutionStrategy of a configuration and individual components can be explicitly acceptedor rejected by rule. Components that are neither accepted or rejected will be subject tothe default version matching strategies.

DependencyAdder

ADependencyAdder is used to add dependencies to a specific configuration.

ExtensionAware

Objects that can be extended at runtime with other objects.

ExtraPropertiesExtension

Additional, ad-hoc, properties for Gradle domain objects.

PluginDependenciesSpec

The DSL for declaring plugins to use in a script.

PluginDependencySpec

A mutable specification of a dependency on a plugin.

PluginManagementSpec

Configures how plugins are resolved.

ResourceHandler

Provides access to resource-specific utility methods, for example factory methods that create various resources.

TextResourceFactory

CreatesTextResources backed by sources such as strings, files, and archive entries.

InputChanges

Provides access to any input files that need to be processed by an incremental work action.

Distribution

A distribution allows to bundle an application or a library including dependencies, sources...

Publishing types

Listed below are the types used to configure publishing:

TypeDescription
PublishingExtension

The configuration of how to “publish” the different components of a project.

IvyPublication

AIvyPublication is the representation/configuration of how Gradle should publish something in Ivy format, to an Ivy repository.You directly add a named Ivy Publication the project'spublishing.publications container by providingIvyPublication as the type.

IvyArtifact

An artifact published as part of aIvyPublication.

IvyArtifactSet

A Collection ofIvyArtifacts to be included in anIvyPublication.Being aDomainObjectSet, aIvyArtifactSet provides convenient methods for querying, filtering, and applying actions to the set ofIvyArtifacts.

IvyModuleDescriptorSpec

The descriptor of any Ivy publication.

IvyModuleDescriptorAuthor

An author of an Ivy publication.

IvyModuleDescriptorLicense

A license of an Ivy publication.

IvyModuleDescriptorDescription

The description of an Ivy publication.

MavenPublication

AMavenPublication is the representation/configuration of how Gradle should publish something in Maven format.You directly add a named Maven Publication the project'spublishing.publications container by providingMavenPublication as the type.

MavenArtifact

An artifact published as part of aMavenPublication.

MavenArtifactSet

A Collection ofMavenArtifacts to be included in aMavenPublication.Being aDomainObjectSet, aMavenArtifactSet provides convenient methods for querying, filtering, and applying actions to the set ofMavenArtifacts.

MavenPom

The POM for a Maven publication.

MavenPomCiManagement

The CI management system of a Maven publication.

MavenPomContributor

A contributor of a Maven publication.

MavenPomContributorSpec

Allows to add contributors of a Maven publication.

MavenPomDeveloper

A developer of a Maven publication.

MavenPomDeveloperSpec

Allows to add developers to a Maven publication.

MavenPomDistributionManagement

The distribution management configuration of a Maven publication.

MavenPomIssueManagement

The issue management system of a Maven publication.

MavenPomLicense

A license of a Maven publication.

MavenPomLicenseSpec

Allows to add licenses to a Maven publication.

MavenPomMailingList

A mailing list of a Maven publication.

MavenPomMailingListSpec

Allows to add mailing lists to a Maven publication.

MavenPomOrganization

The organization of a Maven publication.

MavenPomRelocation

The relocation information of a Maven publication that has been movedto a new group and/or artifact ID.

MavenPomScm

The SCM (source control management) of a Maven publication.

Container types

Container types that handle various declarative elements (e.g. dependencies, configurations, artifacts, tasks, etc.):

TypeDescription
TaskContainer

ATaskContainer is responsible for managing a set ofTask instances.

ConfigurationContainer

AConfigurationContainer is responsible for declaring and managing configurations. See alsoConfiguration.

RepositoryHandler

ARepositoryHandler manages a set of repositories, allowing repositories to be defined and queried.

DependencyHandler

ADependencyHandler is used to declare dependencies. Dependencies are grouped intoconfigurations (seeConfiguration).

ComponentMetadataHandler

Allows the build to provide rules that modify the metadata of depended-on software components.Component metadata rules are applied in the components section of the dependencies blockDependencyHandler of a build script. The rules can be defined in two different ways:

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).

Authentication types

Credentials and Authentication types for connecting to repositories:

TypeDescription
AuthenticationSupported

An artifact repository which supports username/password authentication.

Credentials

Base interface for credentials used for different authentication purposes.(e.g authenticatedRepositoryHandler)

PasswordCredentials

A username/password credentials that can be used to login to password-protected remote repository.

AwsCredentials

Represents credentials used to authenticate with Amazon Web Services.

HttpHeaderCredentials

Credentials that can be used to login to a protected server, e.g. a remote repository by using HTTP header.The properties used for creating credentials from a property arerepoAuthHeaderName andrepoAuthHeaderValue, whererepo is the identity of the repository.

AuthenticationContainer

Container for configuring repository authentication schemes of typeAuthentication.

Authentication

Base interface for transport authentication schemes.

BasicAuthentication

Authentication scheme for basic access authentication over HTTP. When using this scheme, credentials are sent preemptively.

HttpHeaderAuthentication

Authentication scheme for HTTP header authentication over HTTP.

DigestAuthentication

Authentication scheme for digest access authentication over HTTP.

Build Cache types

Types used to connect to and configure the build cache:

TypeDescription
BuildCacheConfiguration

Configuration for thebuild cache for an entire Gradle build.

DirectoryBuildCache

Configuration object for the local directory build cache.

HttpBuildCache

Configuration object for the HTTP build cache.Cache entries are loaded via GET and stored via PUT requests.

Input Normalization types

Types used to configure input normalization

TypeDescription
InputNormalizationHandler

Used to configure input normalization.Currently, it is only possible to configure runtime classpath normalization.

InputNormalization

Input normalization configuration.Input normalization is used when Gradle tries to determine if two task inputs are different.Gradle normalizes both inputs and the inputs are considered different if and only if the normalizations are different.

RuntimeClasspathNormalization

Configuration of runtime classpath normalization.

Help Task types

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.

TypeDescription
TaskReportTask

Displays a list of tasks in the project. An instance of this type is used when you execute thetasks taskfrom the command-line.

ProjectReportTask

Displays a list of projects in the build. An instance of this type is used when you execute theprojectstask from the command-line.

DependencyReportTask

Displays the dependency tree for a project. An instance of this type is used when youexecute thedependencies task from the command-line.

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 theproperties taskfrom the command-line.

ComponentReport

Displays some details about the software components produced by the project.

DependentComponentsReport

Displays dependent components.

ModelReport

Displays some details about the configuration model of the project.An instance of this type is used when you execute themodel task from the command-line.

OutgoingVariantsReportTask

A task which reports the outgoing variants of a project on the command line.This is useful for listing what a project produces in terms of variants andwhat artifacts are attached to each variant.Variants, in this context, must be understood as "things produced by a projectwhich can safely be consumed by another project".

ResolvableConfigurationsReportTask

A task which reports the configurations of a project which can be resolved on the command line.This is useful for determining which attributes are associated with the resolvableconfigurations being used to resolve a project's dependencies. The output can help predict which variant ofeach dependency will be resolved.

Task types

Listed below are the various task types which are available for use in your build script:

TypeDescription
AntlrTask

Generates parsers from Antlr grammars.

BuildEnvironmentReportTask

Provides information about the build environment for the project that the task is associated with.

Checkstyle

Runs Checkstyle against some source files.

CodeNarc

Runs CodeNarc against some source files.

Copy

Copies files into a destination directory. This task can also rename and filter files as it copies. The taskimplementsCopySpec for specifying what to copy.

CreateStartScripts

Creates start scripts for launching JVM applications.

Delete

Deletes files or directories. Example:

Ear

Assembles an EAR archive.

Exec

Executes a command line process. Example:

GenerateIvyDescriptor

Generates an Ivy XML Module Descriptor file.

GenerateMavenPom

Generates a Maven module descriptor (POM) 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.

HtmlDependencyReportTask

Generates an HTML dependency report. This reportcombines the features of the ASCII dependency report and those of the ASCIIdependency insight report. For a given project, it generates a tree of the dependenciesof every configuration, and each dependency can be clicked to show the insight ofthis dependency.

JacocoReport

Task to generate HTML, Xml and CSV reports of Jacoco coverage data.

JacocoCoverageVerification

Task for verifying code coverage metrics. Fails the task if violations are detected based on specified rules.

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.

Pmd

Runs a set of static code analysis rules on Java source code files and generates a report of problems found.

ProcessResources

Copies resources from their source to their target directory, potentially processing them.Makes sure no stale resources remain in the target directory.

PublishToIvyRepository

Publishes an IvyPublication to an IvyArtifactRepository.

PublishToMavenRepository

Publishes aMavenPublication to aMavenArtifactRepository.

ScalaCompile

Compiles Scala source files, and optionally, Java source files.

ScalaDoc

Generates HTML API documentation for Scala source files.

InitBuild

Generates a Gradle project structure.

Sign

A task for creating digital signature files for one or more; tasks, files, publishable artifacts or configurations.

Sync

Synchronizes the contents of a destination directory with some source directories and files.

Tar

Assembles a TAR archive.

AbstractTestTask

Abstract class for all test tasks.

Test

Executes JUnit (3.8.x, 4.x or 5.x) or TestNG tests. Test are always run in (one or more) separate JVMs.

TestReport

Generates an HTML test report from the results of one or moreTest tasks.

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.

WriteProperties

Writes aProperties in a way that the results can be expected to be reproducible.

Zip

Assembles a ZIP archive.The default is to compress the contents of the zip.

Test types

Listed below are the tasks and configurable objects related to modeled Test Suites:

TypeDescription
TestingExtension

This DSL element exists to contain a collection ofTestSuites.

TestSuite

Base test suite component. A test suite is a collection of tests.

JvmTestSuite

A test suite is a collection of JVM-based tests.

TestSuiteTarget

Base test suite target.A test suite target is a collection of tests that run in a particular context (operating system, Java runtime, etc).

JvmTestSuiteTarget

Defines the target environment against which aJvmTestSuite will be run.

Test

Executes JUnit (3.8.x, 4.x or 5.x) or TestNG tests. Test are always run in (one or more) separate JVMs.

Dependencies

Universal APIs that are available for alldependencies blocks.

GradleDependencies

Dependency APIs available fordependencies blocks that can build software that relies on Gradle APIs.

TestFixturesDependencyModifiers

Dependency modifier APIs that can find test fixtures in other modules fordependencies blocks.

PlatformDependencyModifiers

Dependency modifier APIs that can find platform and enforced platforms in other modules fordependencies blocks.

JvmComponentDependencies

This DSL element is used to add dependencies to a component, likeJvmTestSuite.

Reporting types

Listed below are some of the types which are used when generating reports:

TypeDescription
CustomizableHtmlReport

A HTML Report whose generation can be customized with a XSLT stylesheet.

SingleFileReport

A report that is a single file.

DirectoryReport

A directory based report to be created.

Report

A file based report to be created.

Reporting

An object that provides reporting options.

ReportContainer

A container ofReport objects, that represent potential reports.

ReportingExtension

A project extension named "reporting" that provides basic reporting settings and utilities.

AggregateTestReport

A container for the inputs of an aggregated test report.

JacocoCoverageReport

A container for the inputs of an aggregated JaCoCo code coverage report.

Eclipse/IDEA model types

Used to configure Eclipse or IDEA plugins

TypeDescription
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 theGenerateEclipseClasspath task to generate an Eclipse .classpath file.

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.

Eclipse/IDEA task types

Tasks contributed by IDE plugins. To configure IDE plugins please use IDE model types.

TypeDescription
GenerateEclipseProject

Generates an Eclipse.project file. If you want to fine tune the eclipse configuration

GenerateEclipseClasspath

Generates an Eclipse.classpath file. If you want to fine tune the eclipse configuration

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.

Xcode task types

Tasks contributed by Xcode IDE plugins. To configure IDE plugins please use IDE model types.

TypeDescription
GenerateSchemeFileTask

Task for generating a Xcode scheme file (e.g.Foo.xcodeproj/xcshareddata/xcschemes/Foo.xcscheme). An Xcode scheme defines a collection of targets to build, a configuration to use when building, and a collection of tests to execute.

GenerateWorkspaceSettingsFileTask

Task for generating a Xcode workspace settings file (e.g.Foo.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings).

GenerateXcodeProjectFileTask

Task for generating a Xcode project file (e.g.Foo.xcodeproj/project.pbxproj). A project contains all the elements used to build your products and maintains the relationships between those elements. It contains one or more targets, which specify how to build products. A project defines default build settings for all the targets in the project (each target can also specify its own build settings, which override the project build settings).

GenerateXcodeWorkspaceFileTask

Task for generating a Xcode workspace file (e.g.Foo.xcworkspace/contents.xcworkspacedata). A workspace can contain any number of Xcode projects.

Visual Studio task types

Tasks contributed by Visual Studio IDE plugins. To configure IDE plugins please use IDE model types.

TypeDescription
GenerateSolutionFileTask

Task for generating a Visual Studio solution file (e.g.foo.sln).

GenerateProjectFileTask

Task for generating a Visual Studio project file (e.g.foo.vcxproj).

GenerateFiltersFileTask

Task for generating a Visual Studio filters file (e.g.foo.vcxproj.filters).

Artifact transform types

Used to define artifact transforms.

TypeDescription
TransformAction

Interface for artifact transform actions.

TransformOutputs

The outputs of the artifact transform.

TransformSpec

Base configuration for artifact transform registrations.

Native tool chains model types

Used to configure tool chains for building C++ and Swift components.

TypeDescription
Gcc

TheGNU GCC tool chain.

Clang

TheClang tool chain.

VisualCpp

The Visual C++ tool chain.

Swiftc

TheSwift Compiler tool chain.

Native software model types

Used to configure software components developed with native code.

TypeDescription
PrebuiltLibrary

A library component that is not built by gradle.

PrebuiltSharedLibraryBinary

A shared library that exists at a known location on the filesystem.

PrebuiltStaticLibraryBinary

A static library that exists at a known location on the filesystem.

NativeComponentSpec

Definition of a software component that is to be built by Gradle to run a on JVM platform.

NativeExecutableSpec

Definition of a native executable component that is to be built by Gradle.

NativeLibrarySpec

Definition of a native library component that is to be built by Gradle.

NativeTestSuiteSpec

A component representing a suite of tests that will be executed together.

CUnitTestSuiteSpec

Test suite of CUnit tests.

GoogleTestTestSuiteSpec

Test suite of Google Test tests.

NativeBinarySpec

Represents a binary artifact that is the result of building a native component.

NativeExecutableBinarySpec

An binary built by Gradle for a native application.

NativeLibraryBinarySpec

Represents a binary artifact that is the result of building a native library component.

SharedLibraryBinarySpec

A shared library binary built by Gradle for a native library.

StaticLibraryBinarySpec

A static library binary built by Gradle for a native library.

NativeTestSuiteBinarySpec

An executable which runs a suite of tests.

CUnitTestSuiteBinarySpec

An executable which run a CUnit test suite.

GoogleTestTestSuiteBinarySpec

An executable which run a Google Test test suite.

NativePlatform

A target platform for building native binaries. Each target platform is given a name, and may optionally be givena specificArchitecture and/orOperatingSystem to target.

BuildType

Specifies a build-type for a native binary. Common build types are 'debug' and 'release', but others may be defined.

Flavor

Defines a custom variant that differentiate aNativeBinary.

AssemblerSourceSet

A set of assembly language sources.

CSourceSet

A set of C source files.

CppSourceSet

A set of C++ source files.

ObjectiveCSourceSet

A set of Objective-C source files.

ObjectiveCppSourceSet

A set of Objective-C++ source files.

WindowsResourceSet

A set of Windows Resource definition files.

VisualStudioProject

A visual studio project, created from one or more native binaries.

VisualStudioSolution

A visual studio solution, representing one or more native binaries in a build.

NativeExecutable

An executable native component that is built by Gradle.

NativeLibrary

A library component that is built by a gradle project.

NativeBinary

Represents a particular binary artifact.

NativeExecutableBinary

A binary artifact for aNativeExecutable, targeted at a particular platform with specific configuration.

SharedLibraryBinary

ANativeLibrary that has been compiled and linked as a shared library.

StaticLibraryBinary

ANativeLibrary that has been compiled and archived into a static library.

C++ component model types

Used to configure C++ components.

TypeDescription
CppApplication

Configuration for a C++ application, defining the source files that make up the application plus other settings.

CppLibrary

Configuration for a C++ library, defining the source files and header directories that make up the library plus other settings.

CppTestSuite

A C++ test suite.

Swift component model types

Used to configure Swift components.

TypeDescription
SwiftApplication

Configuration for a Swift application, defining the source files that make up the application plus other settings.

SwiftLibrary

Configuration for a Swift library, defining the source files that make up the library plus other settings.

SwiftXCTestSuite

A XCTest suite, implemented in Swift.

Native binary task types

Tasks used to build native binaries.

TypeDescription
CppCompile

Compiles C++ source files into object files.

SwiftCompile

Compiles Swift source files into object files.

LinkExecutable

Links a binary executable from object files and libraries.

LinkSharedLibrary

Links a binary shared library from object files and imported libraries.

CreateStaticLibrary

Assembles a static library from object files.

LinkMachOBundle

Links a binary bundle from object files and imported libraries.

InstallExecutable

Installs an executable with it's dependent libraries so it can be easily executed.

InstallXCTestBundle

Creates a XCTest bundle with a run script so it can be easily executed.

RunTestExecutable

Runs a compiled and installed test executable.

XCTest

Executes XCTest tests. Test are always run in a single execution.

Native binary task types

Tasks used to build native binaries.

TypeDescription
CCompile

Compiles C source files into object files.

Assemble

Translates Assembly language source files into object files.

ObjectiveCCompile

Compiles Objective-C source files into object files.

ObjectiveCppCompile

Compiles Objective-C++ source files into object files.

WindowsResourceCompile

Compiles Windows Resource scripts into .res files.

©Gradle Inc. All rights reserved.
gradle
Careers |Privacy |Terms of Service |Contact

[8]ページ先頭

©2009-2025 Movatter.jp