Movatterモバイル変換


[0]ホーム

URL:


Project

Table of Contents

Lifecycle
Tasks
Dependencies
Multi-project Builds
Plugins
Dynamic Project Properties
Properties
Methods
Script blocks
Property details
Method details
Script block details
API Documentation: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.

Lifecycle

There is a one-to-one relationship between aProject and abuild.gradlefile. During build initialisation, Gradle assembles aProject object for each project which is toparticipate in the build, as follows:

  • Create aSettings instance for the build.
  • Evaluate thesettings.gradle script, ifpresent, against theSettings object to configure it.
  • Use the configuredSettings object to create the hierarchy ofProject instances.
  • Finally, evaluate eachProject by executing itsbuild.gradle file, ifpresent, against the project. The projects are evaluated in breadth-wise order, such that a project is evaluatedbefore its child projects. This order can be overridden by callingProject.evaluationDependsOnChildren() or by adding anexplicit evaluation dependency usingProject.evaluationDependsOn(java.lang.String).

Tasks

A project is essentially a collection ofTask objects. Each task performs some basic piece of work, suchas compiling classes, or running unit tests, or zipping up a WAR file. You add tasks to a project using one of thecreate() methods onTaskContainer, such asTaskContainer.create(java.lang.String). You can locate existingtasks using one of the lookup methods onTaskContainer, such asTaskCollection.getByName(java.lang.String).

Dependencies

A project generally has a number of dependencies it needs in order to do its work. Also, a project generallyproduces a number of artifacts, which other projects can use. Those dependencies are grouped in configurations, andcan be retrieved and uploaded from repositories. You use theConfigurationContainerreturned byProject.getConfigurations() method to manage the configurations. TheDependencyHandler returned byProject.getDependencies() method to manage thedependencies. TheArtifactHandler returned byProject.getArtifacts() method tomanage the artifacts. TheRepositoryHandler returned byProject.getRepositories() method to manage the repositories.

Multi-project Builds

Projects are arranged into a hierarchy of projects. A project has a name, and a fully qualified path whichuniquely identifies it in the hierarchy.

Plugins

Plugins can be used to modularise and reuse project configuration.Plugins can be applied using thePluginAware.apply(java.util.Map) method, or by using thePluginDependenciesSpec plugins script block.

Dynamic Project Properties

Gradle executes the project's build file against theProject instance to configure the project. Anyproperty or method which your script uses is delegated through to the associatedProject object. Thismeans, that you can use any of the methods and properties on theProject interface directly in your script.

For example:

defaultTasks('some-task')// Delegates to Project.defaultTasks()reportsDir = file('reports')// Delegates to Project.file() and the Java Plugin

You can also access theProject instance using theproject property. This can make thescript clearer in some cases. For example, you could useproject.name rather thanname toaccess the project's name.

A project has 5 property 'scopes', which it searches for properties. You can access these properties by name inyour build file, or by calling the project'sProject.property(java.lang.String) method. The scopes are:

  • TheProject object itself. This scope includes any property getters and setters declared by theProject implementation class. For example,Project.getRootProject() is accessible as therootProject property. The properties of this scope are readable or writable depending on the presenceof the corresponding getter or setter method.
  • Theextra properties of the project. Each project maintains a map of extra properties, whichcan contain any arbitrary name -> value pair. Once defined, the properties of this scope are readable and writable.Seeextra properties for more details.
  • Theextensions added to the project by the plugins. Each extension is available as a read-only property with the same name as the extension.
  • Theconvention properties added to the project by the plugins. A plugin can add properties and methodsto a project through the project'sConvention object. The properties of this scope may be readable or writable, depending on the convention objects.
  • The tasks of the project. A task is accessible by using its name as a property name. The properties of thisscope are read-only. For example, a task calledcompile is accessible as thecompileproperty.
  • The extra properties and convention properties are inherited from the project's parent, recursively up to the rootproject. The properties of this scope are read-only.

When reading a property, the project searches the above scopes in order, and returns the value from the firstscope it finds the property in. If not found, an exception is thrown. SeeProject.property(java.lang.String) for more details.

When writing a property, the project searches the above scopes in order, and sets the property in the first scopeit finds the property in. If not found, an exception is thrown. SeeProject.setProperty(java.lang.String, java.lang.Object) for more details.

Extra Properties

All extra properties must be defined through the "ext" namespace. Once an extra property has been defined,it is available directly on the owning object (in the below case the Project, Task, and sub-projects respectively) and canbe read and updated. Only the initial declaration that needs to be done via the namespace.

project.ext.prop1 ="foo"task doStuff {    ext.prop2 ="bar"}subprojects { ext.${prop3} = false }

Reading extra properties is done through the "ext" or through the owning object.

ext.isSnapshot = version.endsWith("-SNAPSHOT")if (isSnapshot) {// do snapshot stuff}

Dynamic Methods

A project has 5 method 'scopes', which it searches for methods:

  • TheProject object itself.
  • The build file. The project searches for a matching method declared in the build file.
  • Theextensions added to the project by the plugins. Each extension is available as a method which takesa closure orAction as a parameter.
  • Theconvention methods added to the project by the plugins. A plugin can add properties and method toa project through the project'sConvention object.
  • The tasks of the project. A method is added for each task, using the name of the task as the method name andtaking a single closure orAction parameter. The method calls theTask.configure(groovy.lang.Closure) method for theassociated task with the provided closure. For example, if the project has a task calledcompile, then amethod is added with the following signature:void compile(Closure configureClosure).
  • The methods of the parent project, recursively up to the root project.
  • A property of the project whose value is a closure. The closure is treated as a method and called with the provided parameters.The property is located as described above.

Properties

PropertyDescription
allprojects

The set containing this project and its subprojects.

ant

TheAntBuilder for this project. You can use this in your build file to execute anttasks. See example below.

artifacts

Returns a handler for assigning artifacts produced by the project to configurations.

buildDir

The build directory of this project. The build directory is the directory which all artifacts aregenerated into. The default value for the build directory isprojectDir/build

buildFile

The build script for this project.

buildscript

The build script handler for this project. You can use this handler to query details about the buildscript for this project, and manage the classpath used to compile and execute the project's build script.

childProjects

The direct children of this project.

configurations

The configurations of this project.

convention

TheConvention for this project.

defaultTasks

The names of the default tasks of this project. These are used when no tasks names are provided whenstarting the build.

dependencies

The dependency handler of this project. The returned dependency handler instance can be used for addingnew dependencies. For accessing already declared dependencies, the configurations can be used.

dependencyLocking

Provides access to configuring dependency locking

description

The description of this project, if any.

extensions

Allows adding DSL extensions to the project. Useful for plugin authors.

gradle

TheGradle invocation which this project belongs to.

group

The group of this project. Gradle always uses thetoString() value of the group. The groupdefaults to the path with dots as separators.

logger

The logger for this project. You can use this in your build file to write log messages.

logging

TheLoggingManager which can be used to receive logging and to control thestandard output/error capture for this project's build script. By default, System.out is redirected to the Gradlelogging system at the QUIET log level, and System.err is redirected at the ERROR log level.

name

The name of this project. The project's name is not necessarily unique within a project hierarchy. Youshould use theProject.getPath() method for a unique identifier for the project.

normalization

Provides access to configuring input normalization.

parent

The parent project of this project, if any.

path

The path of this project. The path is the fully qualified name of the project.

pluginManager

The plugin manager for this plugin aware object.

plugins

The container of plugins that have been applied to this object.

project

Returns this project. This method is useful in build files to explicitly access project properties andmethods. For example, usingproject.name can express your intent better than usingname. This method also allows you to access project properties from a scope where the property maybe hidden, such as, for example, from a method or closure.

projectDir

The directory containing the project build file.

properties

The properties of this project. Seehere for details of the properties whichare available for a project.

repositories

Returns a handler to create repositories which are used for retrieving dependencies and uploading artifactsproduced by the project.

resources

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

rootDir

The root directory of this project. The root directory is the project directory of the rootproject.

rootProject

The root project for the hierarchy that this project belongs to. In the case of a single-projectbuild, this method returns this project.

state

The evaluation state of this project. You can use this to access information about the evaluation of thisproject, such as whether it has failed.

status

The status of this project. Gradle always uses thetoString() value of the status. The statusdefaults torelease.

subprojects

The set containing the subprojects of this project.

tasks

The tasks of this project.

version

The version of this project. Gradle always uses thetoString() value of the version. Theversion defaults tounspecified.

Properties added by theapplication plugin

PropertyDescription
application

TheJavaApplication added by the application plugin.

applicationDefaultJvmArgs

Array of string arguments to pass to the JVM when running the application

applicationDistribution

The specification of the contents of the distribution.

applicationName

The name of the application.

executableDir

Directory to place executables in

mainClassName

The fully qualified name of the application's main class.

Properties added by thecheckstyle plugin

PropertyDescription
checkstyle

TheCheckstyleExtension added by the checkstyle plugin.

Properties added by thecodenarc plugin

PropertyDescription
codenarc

TheCodeNarcExtension added by the codenarc plugin.

Properties added by thedistribution plugin

PropertyDescription
distributions

TheDistributionContainer added by the distribution plugin.

Properties added by theear plugin

PropertyDescription
appDirName

The name of the application directory, relative to the project directory.Default is "src/main/application".

deploymentDescriptor

A custom deployment descriptor configuration.Default is an "application.xml" with sensible defaults.

generateDeploymentDescriptor
Incubating

Specifies if the deploymentDescriptor should be generated if it does not exist.Default is true.

libDirName

The name of the library directory in the EAR file.Default is "lib".

Properties added by theeclipse plugin

PropertyDescription
eclipse

TheEclipseModel added by the eclipse plugin.

Properties added by theidea plugin

PropertyDescription
idea

TheIdeaModel added by the idea plugin.

Properties added by thejacoco plugin

PropertyDescription
jacoco

TheJacocoPluginExtension added by the jacoco plugin.

Properties added by thejava plugin

PropertyDescription
archivesBaseName

The base name to use for archive files.

distsDir
Deprecated

The directory to generate TAR and ZIP archives into.

distsDirName

The name for the distributions directory. This in interpreted relative to the project' build directory.

distsDirectory

The directory to generate TAR and ZIP archives into.

docsDir

Returns a file pointing to the root directory supposed to be used for all docs.

docsDirName

The name of the docs directory. Can be a name or a path relative to the build dir.

libsDir
Deprecated

The directory to generate JAR and WAR archives into.

libsDirName

The name for the libs directory. This in interpreted relative to the project' build directory.

libsDirectory

The directory to generate JAR and WAR archives into.

reporting

TheReportingExtension added by the java plugin.

sourceCompatibility

The source compatibility used for compiling Java sources.

sourceCompatibility

The source compatibility used for compiling Java sources.

sourceSets

The source sets container.

targetCompatibility

The target compatibility used for compiling Java sources.

targetCompatibility

The target compatibility used for compiling Java sources.

testReportDir

Returns a file pointing to the root directory to be used for reports.

testReportDirName

The name of the test reports directory. Can be a name or a path relative toReportingExtension.getBaseDir().

testResultsDir

Returns a file pointing to the root directory of the test results.

testResultsDirName

The name of the test results directory. Can be a name or a path relative to the build dir.

toolchain
Incubating

Gets the project wide toolchain requirements that will be used for tasks requiring a tool from the toolchain (e.g.JavaCompile).

Properties added by themaven plugin

PropertyDescription
conf2ScopeMappings

The set of rules for how to map Gradle dependencies to Maven scopes.

mavenPomDir

The directory to generate Maven POMs into.

Properties added by thepmd plugin

PropertyDescription
pmd

ThePmdExtension added by the pmd plugin.

Properties added by theproject-report plugin

PropertyDescription
projectReportDir

The directory to generate the project reports into.

projectReportDirName

The name of the directory to generate the project reports into, relative to the project's reports dir.

Properties added by thepublishing plugin

PropertyDescription
publishing

ThePublishingExtension added by the publishing plugin.

Properties added by thesigning plugin

PropertyDescription
signing

TheSigningExtension added by the signing plugin.

Properties added by thevisual-studio plugin

PropertyDescription
visualStudio

TheVisualStudioRootExtension added by the visual-studio plugin.

Properties added by thewar plugin

PropertyDescription
webAppDir

The web application directory.

webAppDirName

The name of the web application directory, relative to the project directory.

Properties added by thexcode plugin

PropertyDescription
xcode

TheXcodeRootExtension added by the xcode plugin.

Methods

MethodDescription
absoluteProjectPath(path)

Converts a name to an absolute project path, resolving names relative to this project.

afterEvaluate(closure)

Adds a closure to be called immediately after this project has been evaluated. The project is passed to theclosure as a parameter. Such a listener gets notified when the build file belonging to this project has beenexecuted. A parent project may for example add such a listener to its child project. Such a listener can furtherconfigure those child projects based on the state of the child projects after their build files have beenrun.

afterEvaluate(action)

Adds an action to execute immediately after this project is evaluated.

allprojects(action)

Configures this project and each of its sub-projects.

ant(configureAction)

Executes the given action against theAntBuilder for this project. You can use this in yourbuild file to execute ant tasks. See example in javadoc forProject.getAnt()

apply(closure)

Applies zero or more plugins or scripts.

apply(options)

Applies a plugin or script, using the given options provided as a map. Does nothing if the plugin has already been applied.

apply(action)

Applies zero or more plugins or scripts.

artifacts(configureAction)

Configures the published artifacts for this project.

beforeEvaluate(closure)

Adds a closure to be called immediately before this project is evaluated. The project is passed to the closureas a parameter.

beforeEvaluate(action)

Adds an action to execute immediately before this project is evaluated.

configure(objects, configureClosure)

Configures a collection of objects via a closure. This is equivalent to callingProject.configure(java.lang.Object, groovy.lang.Closure) for each of the given objects.

configure(objects, configureAction)

Configures a collection of objects via an action.

configure(object, configureClosure)

Configures an object via a closure, with the closure's delegate set to the supplied object. This way you don'thave to specify the context of a configuration statement multiple times.

container(type)

Creates a container for managing named objects of the specified type. The specified type must have a public constructor which takes the name as a String parameter.

container(type, factoryClosure)

Creates a container for managing named objects of the specified type. The given closure is used to create object instances. The name of the instance to be created is passed as a parameter tothe closure.

container(type, factory)

Creates a container for managing named objects of the specified type. The given factory is used to create object instances.

copy(closure)

Copies the specified files. The given closure is used to configure aCopySpec, which is then used tocopy the files. Example:

copy(action)

Copies the specified files. The given action is used to configure aCopySpec, which is then used tocopy the files.

copySpec()

Creates aCopySpec which can later be used to copy files or create an archive.

copySpec(closure)

Creates aCopySpec which can later be used to copy files or create an archive. The given closure is usedto configure theCopySpec before it is returned by this method.

copySpec(action)

Creates aCopySpec which can later be used to copy files or create an archive. The given action is usedto configure theCopySpec before it is returned by this method.

defaultTasks(defaultTasks)

Sets the names of the default tasks of this project. These are used when no tasks names are provided whenstarting the build.

delete(paths)

Deletes files and directories.

delete(action)

Deletes the specified files. The given action is used to configure aDeleteSpec, which is then used todelete the files.

dependencyLocking(configuration)

Configures dependency locking

evaluationDependsOn(path)

Declares that this project has an evaluation dependency on the project with the given path.

exec(closure)

Executes an external command. The closure configures aExecSpec.

exec(action)

Executes an external command.

file(path)

Resolves a file path relative to the project directory of this project. This method converts the supplied pathbased on its type:

file(path, validation)

Resolves a file path relative to the project directory of this project and validates it using the givenscheme. SeePathValidation for the list of possible validations.

fileTree(baseDir)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas perProject.file(java.lang.Object).

fileTree(baseDir, configureClosure)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas perProject.file(java.lang.Object). The closure will be used to configure the new file tree.The file tree is passed to the closure as its delegate. Example:

fileTree(baseDir, configureAction)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas perProject.file(java.lang.Object). The action will be used to configure the new file tree. Example:

fileTree(args)

Creates a newConfigurableFileTree using the provided map of arguments. The map will be applied asproperties on the new file tree. Example:

files(paths, configureClosure)

Creates a newConfigurableFileCollection using the given paths. The paths are evaluated as perProject.files(java.lang.Object[]). The file collection is configured using the given closure. The file collection is passed tothe closure as its delegate. Example:

files(paths, configureAction)

Creates a newConfigurableFileCollection using the given paths. The paths are evaluated as perProject.files(java.lang.Object[]). The file collection is configured using the given action. Example:

files(paths)

Returns aConfigurableFileCollection containing the given files. You can pass any of the followingtypes to this method:

findProject(path)

Locates a project by path. If the path is relative, it is interpreted relative to this project.

findProperty(propertyName)

Returns the value of the given property or null if not found.This method locates a property as follows:

getAllTasks(recursive)

Returns a map of the tasks contained in this project, and optionally its subprojects.

getTasksByName(name, recursive)

Returns the set of tasks with the given name contained in this project, and optionally its subprojects.NOTE: This is an expensive operation since it requires all projects to be configured.

hasProperty(propertyName)

Determines if this project has the given property. Seehere for details of theproperties which are available for a project.

javaexec(closure)

Executes a Java main class. The closure configures aJavaExecSpec.

javaexec(action)

Executes an external Java process.

mkdir(path)

Creates a directory and returns a file pointing to it.

normalization(configuration)

Configures input normalization.

project(path)

Locates a project by path. If the path is relative, it is interpreted relative to this project.

project(path, configureClosure)

Locates a project by path and configures it using the given closure. If the path is relative, it isinterpreted relative to this project. The target project is passed to the closure as the closure's delegate.

project(path, configureAction)

Locates a project by path and configures it using the given action. If the path is relative, it isinterpreted relative to this project.

property(propertyName)

Returns the value of the given property. This method locates a property as follows:

relativePath(path)

Returns the relative path from the project directory to the given path. The given path object is (logically)resolved as described forProject.file(java.lang.Object), from which a relative path is calculated.

relativeProjectPath(path)

Converts a name to a project path relative to this project.

setProperty(name, value)

Sets a property of this project. This method searches for a property with the given name in the followinglocations, and sets the property on the first location where it finds the property.

subprojects(action)

Configures the sub-projects of this project

sync(action)

Synchronizes the contents of a destination directory with some source directories and files.The given action is used to configure aCopySpec, which is then used to synchronize the files.

tarTree(tarPath)

Creates a newFileTree which contains the contents of the given TAR file. The given tarPath path can be:

task(name)

Creates aTask with the given name and adds it to this project. Calling this method is equivalent tocallingProject.task(java.util.Map, java.lang.String) with an empty options map.

task(name, configureClosure)

Creates aTask with the given name and adds it to this project. Before the task is returned, the givenclosure is executed to configure the task.

task(name, configureAction)

Creates aTask with the given name and adds it to this project. Before the task is returned, the givenaction is executed to configure the task.

task(args, name)

Creates aTask with the given name and adds it to this project. A map of creation options can bepassed to this method to control how the task is created. The following options are available:

task(args, name, configureClosure)

Creates aTask with the given name and adds it to this project. Before the task is returned, the givenclosure is executed to configure the task. A map of creation options can be passed to this method to control howthe task is created. SeeProject.task(java.util.Map, java.lang.String) for the available options.

uri(path)

Resolves a file path to a URI, relative to the project directory of this project. Evaluates the provided pathobject as described forProject.file(java.lang.Object), with the exception that any URI scheme is supported, not just'file:' URIs.

zipTree(zipPath)

Creates a newFileTree which contains the contents of the given ZIP file. The given zipPath path isevaluated as perProject.file(java.lang.Object). You can combine this method with theProject.copy(groovy.lang.Closure)method to unzip a ZIP file.

Methods added by theear plugin

MethodDescription
appDirName(appDirName)

Allows changing the application directory.Default is "src/main/application".

deploymentDescriptor(configureAction)

Configures the deployment descriptor for this EAR archive.

libDirName(libDirName)

Allows changing the library directory in the EAR file. Default is "lib".

Methods added by thejava plugin

MethodDescription
disableAutoTargetJvm()

If this method is called, Gradle will not automatically try to fetchdependencies which have a JVM version compatible with the target compatibilityof this module.

manifest()

Creates a new instance of aManifest.

manifest(closure)

Creates and configures a new instance of aManifest. The given closure configuresthe new manifest instance before it is returned.

manifest(action)

Creates and configures a new instance of aManifest.

registerFeature(name, configureAction)

Registers a feature.

toolchain(action)
Incubating

Configures the project wide toolchain requirements for tasks that require a tool from the toolchain (e.g.JavaCompile).

withJavadocJar()
Incubating

Adds a taskjavadocJar that will package the output of thejavadoc task in a JAR with classifierjavadoc.

withSourcesJar()
Incubating

Adds a tasksourcesJar that will package the Java sources of the mainSourceSet in a JAR with classifiersources.

Methods added by themaven plugin

MethodDescription
pom()

Creates a newMavenPom.

pom(configureClosure)

Creates and configures a newMavenPom. The given closure is executed to configure the new POM instance.

pom(configureAction)

Creates and configures a newMavenPom. The given action is executed to configure the new POM instance.

Script blocks

BlockDescription
allprojects

Configures this project and each of its sub-projects.

ant

Executes the given closure against theAntBuilder for this project. You can use this in yourbuild file to execute ant tasks. TheAntBuild is passed to the closure as the closure'sdelegate. See example in javadoc forProject.getAnt()

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.

subprojects

Configures the sub-projects of this project.

Script blocks added by theapplication plugin

BlockDescription
application

Configures theJavaApplication added by the application plugin.

Script blocks added by thecheckstyle plugin

BlockDescription
checkstyle

Configures theCheckstyleExtension added by the checkstyle plugin.

Script blocks added by thecodenarc plugin

BlockDescription
codenarc

Configures theCodeNarcExtension added by the codenarc plugin.

Script blocks added by thedistribution plugin

BlockDescription
distributions

Configures theDistributionContainer added by the distribution plugin.

Script blocks added by theear plugin

BlockDescription
deploymentDescriptor

Configures the deployment descriptor for this EAR archive.

Script blocks added by theeclipse plugin

BlockDescription
eclipse

Configures theEclipseModel added by the eclipse plugin.

Script blocks added by theidea plugin

BlockDescription
idea

Configures theIdeaModel added by the idea plugin.

Script blocks added by thejacoco plugin

BlockDescription
jacoco

Configures theJacocoPluginExtension added by the jacoco plugin.

Script blocks added by thejava plugin

BlockDescription
reporting

Configures theReportingExtension added by the java plugin.

sourceSets

Configures the source sets of this project.

Script blocks added by thepmd plugin

BlockDescription
pmd

Configures thePmdExtension added by the pmd plugin.

Script blocks added by thepublishing plugin

BlockDescription
publishing

Configures thePublishingExtension added by the publishing plugin.

Script blocks added by thesigning plugin

BlockDescription
signing

Configures theSigningExtension added by the signing plugin.

Script blocks added by thevisual-studio plugin

BlockDescription
visualStudio

Configures theVisualStudioRootExtension added by the visual-studio plugin.

Script blocks added by thexcode plugin

BlockDescription
xcode

Configures theXcodeRootExtension added by the xcode plugin.

Property details

Set<Project>allprojects (read-only)

The set containing this project and its subprojects.

AntBuilderant (read-only)

TheAntBuilder for this project. You can use this in your build file to execute anttasks. See example below.

task printChecksum {  doLast {    ant {//using ant checksum task to store the file checksum in the checksumOut ant property      checksum(property:'checksumOut', file:'someFile.txt')//we can refer to the ant property created by checksum task:      println"The checksum is: " + checksumOut    }//we can refer to the ant property later as well:    println"I just love to print checksums: " + ant.checksumOut  }}

Consider following example of ant target:

<target name='printChecksum'>  <checksum property='checksumOut'>    <fileset dir='.'>      <include name='agile.txt'/>    </fileset>  </checksum>  <echo>The checksum is: ${checksumOut}</echo></target>

Here's how it would look like in gradle. Observe how the ant XML is represented in groovy by the ant builder

task printChecksum {  doLast {    ant {      checksum(property:'checksumOut') {        fileset(dir:'.') {          include name:'agile1.txt'        }      }    }    logger.lifecycle("The checksum is $ant.checksumOut")  }}

ArtifactHandlerartifacts (read-only)

Returns a handler for assigning artifacts produced by the project to configurations.

Examples:

See docs forArtifactHandler

FilebuildDir

The build directory of this project. The build directory is the directory which all artifacts aregenerated into. The default value for the build directory isprojectDir/build

FilebuildFile (read-only)

The build script for this project.

If the file exists, it will be evaluated against this project when this project is configured.

ScriptHandlerbuildscript (read-only)

The build script handler for this project. You can use this handler to query details about the buildscript for this project, and manage the classpath used to compile and execute the project's build script.

Map<String,Project>childProjects (read-only)

The direct children of this project.

ConfigurationContainerconfigurations (read-only)

The configurations of this project.

Examples:

See docs forConfigurationContainer

Conventionconvention (read-only)

TheConvention for this project.

You can access this property in your build fileusingconvention. You can also access the properties and methods of the convention objectas if they were properties and methods of this project. Seehere for more details

List<String>defaultTasks

The names of the default tasks of this project. These are used when no tasks names are provided whenstarting the build.

DependencyHandlerdependencies (read-only)

The dependency handler of this project. The returned dependency handler instance can be used for addingnew dependencies. For accessing already declared dependencies, the configurations can be used.

Examples:

See docs forDependencyHandler

DependencyLockingHandlerdependencyLocking (read-only)

Provides access to configuring dependency locking

Stringdescription

The description of this project, if any.

ExtensionContainerextensions (read-only)

Allows adding DSL extensions to the project. Useful for plugin authors.

Gradlegradle (read-only)

TheGradle invocation which this project belongs to.

Objectgroup

The group of this project. Gradle always uses thetoString() value of the group. The groupdefaults to the path with dots as separators.

Loggerlogger (read-only)

The logger for this project. You can use this in your build file to write log messages.

LoggingManagerlogging (read-only)

TheLoggingManager which can be used to receive logging and to control thestandard output/error capture for this project's build script. By default, System.out is redirected to the Gradlelogging system at the QUIET log level, and System.err is redirected at the ERROR log level.

Stringname (read-only)

The name of this project. The project's name is not necessarily unique within a project hierarchy. Youshould use theProject.getPath() method for a unique identifier for the project.

InputNormalizationHandlernormalization (read-only)

Provides access to configuring input normalization.

Projectparent (read-only)

The parent project of this project, if any.

Stringpath (read-only)

The path of this project. The path is the fully qualified name of the project.

PluginManagerpluginManager (read-only)

The plugin manager for this plugin aware object.

PluginContainerplugins (read-only)

The container of plugins that have been applied to this object.

While not deprecated, it is preferred to use the methods of this interface or thePluginAware.getPluginManager() than use the plugin container.

Use one of the 'apply' methods on this interface or on thePluginAware.getPluginManager() to apply plugins instead of applying via the plugin container.

UsePluginManager.hasPlugin(java.lang.String) or similar to query for the application of plugins instead of doing so via the plugin container.

Projectproject (read-only)

Returns this project. This method is useful in build files to explicitly access project properties andmethods. For example, usingproject.name can express your intent better than usingname. This method also allows you to access project properties from a scope where the property maybe hidden, such as, for example, from a method or closure.

FileprojectDir (read-only)

The directory containing the project build file.

Map<String, ?>properties (read-only)

The properties of this project. Seehere for details of the properties whichare available for a project.

RepositoryHandlerrepositories (read-only)

Returns a handler to create repositories which are used for retrieving dependencies and uploading artifactsproduced by the project.

ResourceHandlerresources (read-only)

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

FilerootDir (read-only)

The root directory of this project. The root directory is the project directory of the rootproject.

ProjectrootProject (read-only)

The root project for the hierarchy that this project belongs to. In the case of a single-projectbuild, this method returns this project.

ProjectStatestate (read-only)

The evaluation state of this project. You can use this to access information about the evaluation of thisproject, such as whether it has failed.

Objectstatus

The status of this project. Gradle always uses thetoString() value of the status. The statusdefaults torelease.

The status of the project is only relevant, if you upload libraries together with a module descriptor. Thestatus specified here, will be part of this module descriptor.

Set<Project>subprojects (read-only)

The set containing the subprojects of this project.

TaskContainertasks (read-only)

The tasks of this project.

Objectversion

The version of this project. Gradle always uses thetoString() value of the version. Theversion defaults tounspecified.

JavaApplicationapplication (read-only)

TheJavaApplication added by the application plugin.

Iterable<String>applicationDefaultJvmArgs

Array of string arguments to pass to the JVM when running the application

CopySpecapplicationDistribution

The specification of the contents of the distribution.

Use thisCopySpec to include extra files/resource in the application distribution.

plugins {    id'application'}applicationDistribution.from("some/dir") {  include"*.txt"}

Note that the application plugin pre configures this spec to; include the contents of "src/dist",copy the application start scripts into the "bin" directory, and copy the built jar and its dependenciesinto the "lib" directory.

StringapplicationName

The name of the application.

StringexecutableDir

Directory to place executables in

StringmainClassName

The fully qualified name of the application's main class.

CheckstyleExtensioncheckstyle (read-only)

TheCheckstyleExtension added by the checkstyle plugin.

CodeNarcExtensioncodenarc (read-only)

TheCodeNarcExtension added by the codenarc plugin.

DistributionContainerdistributions (read-only)

TheDistributionContainer added by the distribution plugin.

StringappDirName

The name of the application directory, relative to the project directory.Default is "src/main/application".

DeploymentDescriptordeploymentDescriptor

A custom deployment descriptor configuration.Default is an "application.xml" with sensible defaults.

Property<Boolean>generateDeploymentDescriptor

Note: This property isincubating and may change in a future version of Gradle.

Specifies if the deploymentDescriptor should be generated if it does not exist.Default is true.

StringlibDirName

The name of the library directory in the EAR file.Default is "lib".

EclipseModeleclipse (read-only)

TheEclipseModel added by the eclipse plugin.

IdeaModelidea (read-only)

TheIdeaModel added by the idea plugin.

JacocoPluginExtensionjacoco (read-only)

TheJacocoPluginExtension added by the jacoco plugin.

StringarchivesBaseName

The base name to use for archive files.

FiledistsDir (read-only)

Note: This property isdeprecated and will be removed in the next major version of Gradle.

The directory to generate TAR and ZIP archives into.

This property has been replaced by distsDirectory.

StringdistsDirName

The name for the distributions directory. This in interpreted relative to the project' build directory.

DirectoryPropertydistsDirectory

The directory to generate TAR and ZIP archives into.

FiledocsDir (read-only)

Returns a file pointing to the root directory supposed to be used for all docs.

StringdocsDirName

The name of the docs directory. Can be a name or a path relative to the build dir.

FilelibsDir (read-only)

Note: This property isdeprecated and will be removed in the next major version of Gradle.

The directory to generate JAR and WAR archives into.

This property has been replaced by libsDirectory.

StringlibsDirName

The name for the libs directory. This in interpreted relative to the project' build directory.

DirectoryPropertylibsDirectory

The directory to generate JAR and WAR archives into.

ReportingExtensionreporting (read-only)

TheReportingExtension added by the java plugin.

JavaVersionsourceCompatibility

The source compatibility used for compiling Java sources.

JavaVersionsourceCompatibility

The source compatibility used for compiling Java sources.

SourceSetContainersourceSets (read-only)

The source sets container.

JavaVersiontargetCompatibility

The target compatibility used for compiling Java sources.

JavaVersiontargetCompatibility

The target compatibility used for compiling Java sources.

FiletestReportDir (read-only)

Returns a file pointing to the root directory to be used for reports.

StringtestReportDirName

The name of the test reports directory. Can be a name or a path relative toReportingExtension.getBaseDir().

FiletestResultsDir (read-only)

Returns a file pointing to the root directory of the test results.

StringtestResultsDirName

The name of the test results directory. Can be a name or a path relative to the build dir.

JavaToolchainSpectoolchain (read-only)

Note: This property isincubating and may change in a future version of Gradle.

Gets the project wide toolchain requirements that will be used for tasks requiring a tool from the toolchain (e.g.JavaCompile).

Configuring a toolchain cannot be used together withsourceCompatibility ortargetCompatibility on this extension.Both values will be sourced from the toolchain.

Conf2ScopeMappingContainerconf2ScopeMappings

The set of rules for how to map Gradle dependencies to Maven scopes.

FilemavenPomDir

The directory to generate Maven POMs into.

PmdExtensionpmd (read-only)

ThePmdExtension added by the pmd plugin.

FileprojectReportDir (read-only)

The directory to generate the project reports into.

StringprojectReportDirName

The name of the directory to generate the project reports into, relative to the project's reports dir.

PublishingExtensionpublishing (read-only)

ThePublishingExtension added by the publishing plugin.

SigningExtensionsigning (read-only)

TheSigningExtension added by the signing plugin.

VisualStudioRootExtensionvisualStudio (read-only)

TheVisualStudioRootExtension added by the visual-studio plugin.

FilewebAppDir (read-only)

The web application directory.

StringwebAppDirName

The name of the web application directory, relative to the project directory.

XcodeRootExtensionxcode (read-only)

TheXcodeRootExtension added by the xcode plugin.

Method details

StringabsoluteProjectPath(String path)

Converts a name to an absolute project path, resolving names relative to this project.

voidafterEvaluate(Closure closure)

Adds a closure to be called immediately after this project has been evaluated. The project is passed to theclosure as a parameter. Such a listener gets notified when the build file belonging to this project has beenexecuted. A parent project may for example add such a listener to its child project. Such a listener can furtherconfigure those child projects based on the state of the child projects after their build files have beenrun.

voidafterEvaluate(Action<? superProject> action)

Adds an action to execute immediately after this project is evaluated.

voidallprojects(Action<? superProject> action)

Configures this project and each of its sub-projects.

This method executes the givenAction against this project and each of its sub-projects.

AntBuilderant(Action<? superAntBuilder> configureAction)

Executes the given action against theAntBuilder for this project. You can use this in yourbuild file to execute ant tasks. See example in javadoc forProject.getAnt()

voidapply(Closure closure)

Applies zero or more plugins or scripts.

The given closure is used to configure anObjectConfigurationAction, which “builds” the plugin application.

This method differs fromPluginAware.apply(java.util.Map) in that it allows methods of the configuration action to be invoked more than once.

voidapply(Map<String, ?> options)

Applies a plugin or script, using the given options provided as a map. Does nothing if the plugin has already been applied.

The given map is applied as a series of method calls to a newly createdObjectConfigurationAction.That is, each key in the map is expected to be the name of a methodObjectConfigurationAction and the value to be compatible arguments to that method.

The following options are available:

  • from: A script to apply. Accepts any path supported byProject.uri(java.lang.Object).
  • plugin: The id or implementation class of the plugin to apply.
  • to: The target delegate object or objects. The default is this plugin aware object. Use this to configure objects other than this object.

voidapply(Action<? superObjectConfigurationAction> action)

Applies zero or more plugins or scripts.

The given closure is used to configure anObjectConfigurationAction, which “builds” the plugin application.

This method differs fromPluginAware.apply(java.util.Map) in that it allows methods of the configuration action to be invoked more than once.

voidartifacts(Action<? superArtifactHandler> configureAction)

Configures the published artifacts for this project.

This method executes the given action against theArtifactHandler for this project.

Example:

configurations {//declaring new configuration that will be used to associate with artifacts  schema}task schemaJar(type: Jar) {//some imaginary task that creates a jar artifact with the schema}//associating the task that produces the artifact with the configurationartifacts {//configuration name and the task:  schema schemaJar}

voidbeforeEvaluate(Closure closure)

Adds a closure to be called immediately before this project is evaluated. The project is passed to the closureas a parameter.

voidbeforeEvaluate(Action<? superProject> action)

Adds an action to execute immediately before this project is evaluated.

Iterable<?>configure(Iterable<?> objects,Closure configureClosure)

Configures a collection of objects via a closure. This is equivalent to callingProject.configure(java.lang.Object, groovy.lang.Closure) for each of the given objects.

Iterable<T>configure(Iterable<T> objects,Action<? superT> configureAction)

Configures a collection of objects via an action.

Objectconfigure(Object object,Closure configureClosure)

Configures an object via a closure, with the closure's delegate set to the supplied object. This way you don'thave to specify the context of a configuration statement multiple times.

Instead of:

MyType myType =new MyType()myType.doThis()myType.doThat()

you can do:

MyType myType = configure(new MyType()) {    doThis()    doThat()}

The object being configured is also passed to the closure as a parameter, so you can access it explicitly ifrequired:

configure(someObj) { obj -> obj.doThis() }

NamedDomainObjectContainer<T>container(Class<T> type)

Creates a container for managing named objects of the specified type. The specified type must have a public constructor which takes the name as a String parameter.

All objectsMUST expose their name as a bean property named "name". The name must be constant for the life of the object.

NamedDomainObjectContainer<T>container(Class<T> type,Closure factoryClosure)

Creates a container for managing named objects of the specified type. The given closure is used to create object instances. The name of the instance to be created is passed as a parameter tothe closure.

All objectsMUST expose their name as a bean property named "name". The name must be constant for the life of the object.

Creates a container for managing named objects of the specified type. The given factory is used to create object instances.

All objectsMUST expose their name as a bean property named "name". The name must be constant for the life of the object.

WorkResultcopy(Closure closure)

Copies the specified files. The given closure is used to configure aCopySpec, which is then used tocopy the files. Example:

copy {   from configurations.runtimeClasspath   into'build/deploy/lib'}

Note that CopySpecs can be nested:

copy {   into'build/webroot'   exclude'**/.svn/**'   from('src/main/webapp') {      include'**/*.jsp'      filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1'])   }   from('src/main/js') {      include'**/*.js'   }}

WorkResultcopy(Action<? superCopySpec> action)

Copies the specified files. The given action is used to configure aCopySpec, which is then used tocopy the files.

CopySpeccopySpec()

Creates aCopySpec which can later be used to copy files or create an archive.

CopySpeccopySpec(Closure closure)

Creates aCopySpec which can later be used to copy files or create an archive. The given closure is usedto configure theCopySpec before it is returned by this method.

def baseSpec = copySpec {   from"source"   include"**/*.java"}task copy(type: Copy) {   into"target"   with baseSpec}

CopySpeccopySpec(Action<? superCopySpec> action)

Creates aCopySpec which can later be used to copy files or create an archive. The given action is usedto configure theCopySpec before it is returned by this method.

voiddefaultTasks(String... defaultTasks)

Sets the names of the default tasks of this project. These are used when no tasks names are provided whenstarting the build.

booleandelete(Object... paths)

Deletes files and directories.

This will not follow symlinks. If you need to follow symlinks too useProject.delete(org.gradle.api.Action).

WorkResultdelete(Action<? superDeleteSpec> action)

Deletes the specified files. The given action is used to configure aDeleteSpec, which is then used todelete the files.

Example:

project.delete {    delete'somefile'    followSymlinks = true}

voiddependencyLocking(Action<? superDependencyLockingHandler> configuration)

Configures dependency locking

ProjectevaluationDependsOn(String path)

Declares that this project has an evaluation dependency on the project with the given path.

ExecResultexec(Closure closure)

Executes an external command. The closure configures aExecSpec.

ExecResultexec(Action<? superExecSpec> action)

Executes an external command.

The given action configures aExecSpec, which is used to launch the process.This method blocks until the process terminates, with its result being returned.

Filefile(Object path)

Resolves a file path relative to the project directory of this project. This method converts the supplied pathbased on its type:

  • ACharSequence, includingString orGString. Interpreted relative to the project directory. A string that starts withfile: is treated as a file URL.
  • AFile. If the file is an absolute file, it is returned as is. Otherwise, the file's path isinterpreted relative to the project directory.
  • APath. The path must be associated with the default provider and is treated thesame way as an instance ofFile.
  • AURI orURL. The URL's path is interpreted as the file path. Onlyfile: URLs are supported.
  • ADirectory orRegularFile.
  • AProvider of any supported type. The provider's value is resolved recursively.
  • ATextResource.
  • A GroovyClosure or Kotlin function that returns any supported type. The closure's return value is resolved recursively.
  • ACallable that returns any supported type. The callable's return value is resolved recursively.

Filefile(Object path,PathValidation validation)

Resolves a file path relative to the project directory of this project and validates it using the givenscheme. SeePathValidation for the list of possible validations.

ConfigurableFileTreefileTree(Object baseDir)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas perProject.file(java.lang.Object).

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

def myTree = fileTree("src")myTree.include"**/*.java"myTree.builtBy"someTask"task copy(type: Copy) {   from myTree}

The order of the files in aFileTree is not stable, even on a single computer.

ConfigurableFileTreefileTree(Object baseDir,Closure configureClosure)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas perProject.file(java.lang.Object). The closure will be used to configure the new file tree.The file tree is passed to the closure as its delegate. Example:

def myTree = fileTree('src') {   exclude'**/.data/**'   builtBy'someTask'}task copy(type: Copy) {   from myTree}

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

The order of the files in aFileTree is not stable, even on a single computer.

ConfigurableFileTreefileTree(Object baseDir,Action<? superConfigurableFileTree> configureAction)

Creates a newConfigurableFileTree using the given base directory. The given baseDir path is evaluatedas perProject.file(java.lang.Object). The action will be used to configure the new file tree. Example:

def myTree = fileTree('src') {   exclude'**/.data/**'   builtBy'someTask'}task copy(type: Copy) {   from myTree}

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

The order of the files in aFileTree is not stable, even on a single computer.

ConfigurableFileTreefileTree(Map<String, ?> args)

Creates a newConfigurableFileTree using the provided map of arguments. The map will be applied asproperties on the new file tree. Example:

def myTree = fileTree(dir:'src', excludes:['**/ignore/**','**/.data/**'])task copy(type: Copy) {    from myTree}

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

The order of the files in aFileTree is not stable, even on a single computer.

ConfigurableFileCollectionfiles(Object paths,Closure configureClosure)

Creates a newConfigurableFileCollection using the given paths. The paths are evaluated as perProject.files(java.lang.Object[]). The file collection is configured using the given closure. The file collection is passed tothe closure as its delegate. Example:

files"$buildDir/classes" {    builtBy'compile'}

The returned file collection is lazy, so that the paths are evaluated only when the contents of the filecollection are queried. The file collection is also live, so that it evaluates the above each time the contentsof the collection is queried.

Creates a newConfigurableFileCollection using the given paths. The paths are evaluated as perProject.files(java.lang.Object[]). The file collection is configured using the given action. Example:

files"$buildDir/classes" {    builtBy'compile'}

The returned file collection is lazy, so that the paths are evaluated only when the contents of the filecollection are queried. The file collection is also live, so that it evaluates the above each time the contentsof the collection is queried.

Returns aConfigurableFileCollection containing the given files. You can pass any of the followingtypes to this method:

  • ACharSequence, includingString orGString. Interpreted relative to the project directory, as perProject.file(java.lang.Object). A string that starts withfile: is treated as a file URL.
  • AFile. Interpreted relative to the project directory, as perProject.file(java.lang.Object).
  • APath, as perProject.file(java.lang.Object).
  • AURI orURL. The URL's path is interpreted as a file path. Onlyfile: URLs are supported.
  • ADirectory orRegularFile.
  • ACollection,Iterable, or an array that contains objects of any supported type. The elements of the collection are recursively converted to files.
  • AFileCollection. The contents of the collection are included in the returned collection.
  • AFileTree orDirectoryTree. The contents of the tree are included in the returned collection.
  • AProvider of any supported type. The provider's value is recursively converted to files. If the provider represents an output of a task, that task is executed if the file collection is used as an input to another task.
  • ACallable that returns any supported type. The return value of thecall() method is recursively converted to files. Anull return value is treated as an empty collection.
  • A GroovyClosure or Kotlin function that returns any of the types listed here. The return value of the closure is recursively converted to files. Anull return value is treated as an empty collection.
  • ATask. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.
  • ATaskOutputs. Converted to the output files the related task. The task is executed if the file collection is used as an input to another task.
  • Anything else is treated as an error.

The returned file collection is lazy, so that the paths are evaluated only when the contents of the filecollection are queried. The file collection is also live, so that it evaluates the above each time the contentsof the collection is queried.

The returned file collection maintains the iteration order of the supplied paths.

The returned file collection maintains the details of the tasks that produce the files, so that these tasks are executed if this file collection is used as an input to some task.

This method can also be used to create an empty collection, which can later be mutated to add elements.

ProjectfindProject(String path)

Locates a project by path. If the path is relative, it is interpreted relative to this project.

ObjectfindProperty(String propertyName)

Returns the value of the given property or null if not found.This method locates a property as follows:

  1. If this project object has a property with the given name, return the value of the property.
  2. If this project has an extension with the given name, return the extension.
  3. If this project's convention object has a property with the given name, return the value of theproperty.
  4. If this project has an extra property with the given name, return the value of the property.
  5. If this project has a task with the given name, return the task.
  6. Search up through this project's ancestor projects for a convention property or extra property with thegiven name.
  7. If not found, null value is returned.

Map<Project,Set<Task>>getAllTasks(boolean recursive)

Returns a map of the tasks contained in this project, and optionally its subprojects.

Set<Task>getTasksByName(String name,boolean recursive)

Returns the set of tasks with the given name contained in this project, and optionally its subprojects.NOTE: This is an expensive operation since it requires all projects to be configured.

booleanhasProperty(String propertyName)

Determines if this project has the given property. Seehere for details of theproperties which are available for a project.

ExecResultjavaexec(Closure closure)

Executes a Java main class. The closure configures aJavaExecSpec.

ExecResultjavaexec(Action<? superJavaExecSpec> action)

Executes an external Java process.

The given action configures aJavaExecSpec, which is used to launch the process.This method blocks until the process terminates, with its result being returned.

Filemkdir(Object path)

Creates a directory and returns a file pointing to it.

voidnormalization(Action<? superInputNormalizationHandler> configuration)

Configures input normalization.

Projectproject(String path)

Locates a project by path. If the path is relative, it is interpreted relative to this project.

Projectproject(String path,Closure configureClosure)

Locates a project by path and configures it using the given closure. If the path is relative, it isinterpreted relative to this project. The target project is passed to the closure as the closure's delegate.

Projectproject(String path,Action<? superProject> configureAction)

Locates a project by path and configures it using the given action. If the path is relative, it isinterpreted relative to this project.

Objectproperty(String propertyName)

Returns the value of the given property. This method locates a property as follows:

  1. If this project object has a property with the given name, return the value of the property.
  2. If this project has an extension with the given name, return the extension.
  3. If this project's convention object has a property with the given name, return the value of theproperty.
  4. If this project has an extra property with the given name, return the value of the property.
  5. If this project has a task with the given name, return the task.
  6. Search up through this project's ancestor projects for a convention property or extra property with thegiven name.
  7. If not found, aMissingPropertyException is thrown.

StringrelativePath(Object path)

Returns the relative path from the project directory to the given path. The given path object is (logically)resolved as described forProject.file(java.lang.Object), from which a relative path is calculated.

StringrelativeProjectPath(String path)

Converts a name to a project path relative to this project.

voidsetProperty(String name,Object value)

Sets a property of this project. This method searches for a property with the given name in the followinglocations, and sets the property on the first location where it finds the property.

  1. The project object itself. For example, therootDir project property.
  2. The project'sConvention object. For example, thesrcRootName java pluginproperty.
  3. The project's extra properties.

If the property is not found, aMissingPropertyException is thrown.

voidsubprojects(Action<? superProject> action)

Configures the sub-projects of this project

This method executes the givenAction against the sub-projects of this project.

WorkResultsync(Action<? superCopySpec> action)

Synchronizes the contents of a destination directory with some source directories and files.The given action is used to configure aCopySpec, which is then used to synchronize the files.

This method is like theProject.copy(org.gradle.api.Action) task, except the destination directory will only contain the files copied.All files that exist in the destination directory will be deleted before copying files, unless a preserve option is specified.

Example:

project.sync {   from'my/shared/dependencyDir'   into'build/deps/compile'}

Note that you can preserve output that already exists in the destination directory:

project.sync {    from'source'    into'dest'    preserve {        include'extraDir/**'        include'dir1/**'        exclude'dir1/extra.txt'    }}

FileTreetarTree(Object tarPath)

Creates a newFileTree which contains the contents of the given TAR file. The given tarPath path can be:

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

Unless custom implementation of resources is passed, the tar tree attempts to guess the compression based on the file extension.

You can combine this method with theProject.copy(groovy.lang.Closure)method to untar a TAR file:

task untar(type: Copy) {  from tarTree('someCompressedTar.gzip')//tar tree attempts to guess the compression based on the file extension//however if you must specify the compression explicitly you can:  from tarTree(resources.gzip('someTar.ext'))//in case you work with unconventionally compressed tars//you can provide your own implementation of a ReadableResource://from tarTree(yourOwnResource as ReadableResource)  into'dest'}

Tasktask(String name)

Creates aTask with the given name and adds it to this project. Calling this method is equivalent tocallingProject.task(java.util.Map, java.lang.String) with an empty options map.

After the task is added to the project, it is made available as a property of the project, so that you canreference the task by name in your build file. Seehere for more details

If a task with the given name already exists in this project, an exception is thrown.

Tasktask(String name,Closure configureClosure)

Creates aTask with the given name and adds it to this project. Before the task is returned, the givenclosure is executed to configure the task.

After the task is added to the project, it is madeavailable as a property of the project, so that you can reference the task by name in your build file. Seehere for more details

Tasktask(String name,Action<? superTask> configureAction)

Creates aTask with the given name and adds it to this project. Before the task is returned, the givenaction is executed to configure the task.

After the task is added to the project, it is madeavailable as a property of the project, so that you can reference the task by name in your build file. Seehere for more details

Tasktask(Map<String, ?> args,String name)

Creates aTask with the given name and adds it to this project. A map of creation options can bepassed to this method to control how the task is created. The following options are available:

OptionDescriptionDefault Value
typeThe class of the task tocreate.DefaultTask
overwriteReplace an existingtask?false
dependsOnA task name or set of task names whichthis task depends on[]
actionA closure orAction to add to thetask.null
descriptionA description of the task.null
groupA task group which this task belongs to.null

After the task is added to the project, it is made available as a property of the project, so that you canreference the task by name in your build file. Seehere for more details

If a task with the given name already exists in this project and theoverride option is not setto true, an exception is thrown.

Tasktask(Map<String, ?> args,String name,Closure configureClosure)

Creates aTask with the given name and adds it to this project. Before the task is returned, the givenclosure is executed to configure the task. A map of creation options can be passed to this method to control howthe task is created. SeeProject.task(java.util.Map, java.lang.String) for the available options.

After the task is added to the project, it is made available as a property of the project, so that you canreference the task by name in your build file. Seehere for more details

If a task with the given name already exists in this project and theoverride option is not setto true, an exception is thrown.

URIuri(Object path)

Resolves a file path to a URI, relative to the project directory of this project. Evaluates the provided pathobject as described forProject.file(java.lang.Object), with the exception that any URI scheme is supported, not just'file:' URIs.

FileTreezipTree(Object zipPath)

Creates a newFileTree which contains the contents of the given ZIP file. The given zipPath path isevaluated as perProject.file(java.lang.Object). You can combine this method with theProject.copy(groovy.lang.Closure)method to unzip a ZIP file.

The returned file tree is lazy, so that it scans for files only when the contents of the file tree arequeried. The file tree is also live, so that it scans for files each time the contents of the file tree arequeried.

voidappDirName(String appDirName)

Allows changing the application directory.Default is "src/main/application".

EarPluginConventiondeploymentDescriptor(Action<? superDeploymentDescriptor> configureAction)

Configures the deployment descriptor for this EAR archive.

The given action is executed to configure the deployment descriptor.

voidlibDirName(String libDirName)

Allows changing the library directory in the EAR file. Default is "lib".

voiddisableAutoTargetJvm()

If this method is called, Gradle will not automatically try to fetchdependencies which have a JVM version compatible with the target compatibilityof this module.

This should be used whenever the default behavior is notapplicable, in particular when for some reason it's not possible to splita module and that this module only has some classes which require dependencieson higher versions.

Manifestmanifest()

Creates a new instance of aManifest.

Manifestmanifest(Closure closure)

Creates and configures a new instance of aManifest. The given closure configuresthe new manifest instance before it is returned.

Manifestmanifest(Action<? superManifest> action)

Creates and configures a new instance of aManifest.

voidregisterFeature(String name,Action<? superFeatureSpec> configureAction)

Registers a feature.

JavaToolchainSpectoolchain(Action<? superJavaToolchainSpec> action)

Note: This method isincubating and may change in a future version of Gradle.

Configures the project wide toolchain requirements for tasks that require a tool from the toolchain (e.g.JavaCompile).

Configuring a toolchain cannot be used together withsourceCompatibility ortargetCompatibility on this extension.Both values will be sourced from the toolchain.

voidwithJavadocJar()

Note: This method isincubating and may change in a future version of Gradle.

Adds a taskjavadocJar that will package the output of thejavadoc task in a JAR with classifierjavadoc.

The produced artifact is registered as a documentation variant on thejava component and added as a dependency on theassemble task.This means that ifmaven-publish orivy-publish is also applied, the javadoc JAR will be published.

If the project already has a task namedjavadocJar then no task is created.

The publishing of the Javadoc variant can also be disabled usingConfigurationVariantDetails.skip()throughAdhocComponentWithVariants.withVariantsFromConfiguration(org.gradle.api.artifacts.Configuration, org.gradle.api.Action),if it should only be built locally by calling or wiring the ':javadocJar' task.

voidwithSourcesJar()

Note: This method isincubating and may change in a future version of Gradle.

Adds a tasksourcesJar that will package the Java sources of the mainSourceSet in a JAR with classifiersources.

The produced artifact is registered as a documentation variant on thejava component and added as a dependency on theassemble task.This means that ifmaven-publish orivy-publish is also applied, the sources JAR will be published.

If the project already has a task namedsourcesJar then no task is created.

The publishing of the sources variant can be disabled usingConfigurationVariantDetails.skip()throughAdhocComponentWithVariants.withVariantsFromConfiguration(org.gradle.api.artifacts.Configuration, org.gradle.api.Action),if it should only be built locally by calling or wiring the ':sourcesJar' task.

Creates a newMavenPom.

MavenPompom(Closure configureClosure)

Creates and configures a newMavenPom. The given closure is executed to configure the new POM instance.

MavenPompom(Action<? superMavenPom> configureAction)

Creates and configures a newMavenPom. The given action is executed to configure the new POM instance.

Script block details

allprojects { }

Configures this project and each of its sub-projects.

This method executes the given closure against this project and its sub-projects. The targetProjectis passed to the closure as the closure's delegate.

Delegates to:
EachProject inallprojects

ant { }

Executes the given closure against theAntBuilder for this project. You can use this in yourbuild file to execute ant tasks. TheAntBuild is passed to the closure as the closure'sdelegate. See example in javadoc forProject.getAnt()

Delegates to:
AntBuilder fromant

artifacts { }

Configures the published artifacts for this project.

This method executes the given closure against theArtifactHandler for this project. TheArtifactHandler is passed to the closure as the closure's delegate.

Example:

configurations {//declaring new configuration that will be used to associate with artifacts  schema}task schemaJar(type: Jar) {//some imaginary task that creates a jar artifact with the schema}//associating the task that produces the artifact with the configurationartifacts {//configuration name and the task:  schema schemaJar}
Delegates to:
ArtifactHandler fromartifacts

buildscript { }

Configures the build script classpath for this project.

The given closure is executed against this project'sScriptHandler. TheScriptHandler ispassed to the closure as the closure's delegate.

Delegates to:
ScriptHandler frombuildscript

configurations { }

Configures the dependency configurations for this project.

This method executes the given closure against theConfigurationContainerfor this project. TheConfigurationContainer is passed to the closure as the closure's delegate.

Examples:

See docs forConfigurationContainer

Delegates to:
ConfigurationContainer fromconfigurations

dependencies { }

Configures the dependencies for this project.

This method executes the given closure against theDependencyHandler for this project. TheDependencyHandler is passed to the closure as the closure's delegate.

Examples:

See docs forDependencyHandler

Delegates to:
DependencyHandler fromdependencies

repositories { }

Configures the repositories for this project.

This method executes the given closure against theRepositoryHandler for this project. TheRepositoryHandler is passed to the closure as the closure's delegate.

Delegates to:
RepositoryHandler fromrepositories

subprojects { }

Configures the sub-projects of this project.

This method executes the given closure against each of the sub-projects of this project. The targetProject is passed to the closure as the closure's delegate.

Delegates to:
EachProject insubprojects

application { }

Configures theJavaApplication added by the application plugin.

Delegates to:
JavaApplication fromapplication

checkstyle { }

Configures theCheckstyleExtension added by the checkstyle plugin.

Delegates to:
CheckstyleExtension fromcheckstyle

codenarc { }

Configures theCodeNarcExtension added by the codenarc plugin.

Delegates to:
CodeNarcExtension fromcodenarc

distributions { }

Configures theDistributionContainer added by the distribution plugin.

Delegates to:
DistributionContainer fromdistributions

deploymentDescriptor { }

Configures the deployment descriptor for this EAR archive.

The given closure is executed to configure the deployment descriptor.TheDeploymentDescriptor is passed to the closure as its delegate.

Delegates to:
DeploymentDescriptor fromdeploymentDescriptor

eclipse { }

Configures theEclipseModel added by the eclipse plugin.

Delegates to:
EclipseModel fromeclipse

idea { }

Configures theIdeaModel added by the idea plugin.

Delegates to:
IdeaModel fromidea

jacoco { }

Configures theJacocoPluginExtension added by the jacoco plugin.

Delegates to:
JacocoPluginExtension fromjacoco

reporting { }

Configures theReportingExtension added by the java plugin.

Delegates to:
ReportingExtension fromreporting

sourceSets { }

Configures the source sets of this project.

The given closure is executed to configure theSourceSetContainer. TheSourceSetContaineris passed to the closure as its delegate.

See the example below howSourceSet 'main' is accessed and how theSourceDirectorySet 'java'is configured to exclude some package from compilation.

plugins {    id'java'}sourceSets {  main {    java {      exclude'some/unwanted/package/**'    }  }}
Delegates to:
SourceSetContainer fromsourceSets

pmd { }

Configures thePmdExtension added by the pmd plugin.

Delegates to:
PmdExtension frompmd

publishing { }

Configures thePublishingExtension added by the publishing plugin.

Delegates to:
PublishingExtension frompublishing

signing { }

Configures theSigningExtension added by the signing plugin.

Delegates to:
SigningExtension fromsigning

visualStudio { }

Configures theVisualStudioRootExtension added by the visual-studio plugin.

Delegates to:
VisualStudioRootExtension fromvisualStudio

xcode { }

Configures theXcodeRootExtension added by the xcode plugin.

Delegates to:
XcodeRootExtension fromxcode

[8]ページ先頭

©2009-2025 Movatter.jp