api / org.gradle.api / Project

Project

interface Project : Comparable<Project>, ExtensionAware, PluginAware

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

Lifecycle

There is a one-to-one relationship between a Project and a {@value #DEFAULT_BUILD_FILE} file. During build initialisation, Gradle assembles a Project object for each project which is to participate in the build, as follows:

Tasks

A project is essentially a collection of Task objects. Each task performs some basic piece of work, such as compiling classes, or running unit tests, or zipping up a WAR file. You add tasks to a project using one of the create() methods on TaskContainer, such as TaskContainer#create(String). You can locate existing tasks using one of the lookup methods on TaskContainer, such as org.gradle.api.tasks.TaskCollection#getByName(String).

Dependencies

A project generally has a number of dependencies it needs in order to do its work. Also, a project generally produces a number of artifacts, which other projects can use. Those dependencies are grouped in configurations, and can be retrieved and uploaded from repositories. You use the org.gradle.api.artifacts.ConfigurationContainer returned by #getConfigurations() method to manage the configurations. The returned by #getDependencies() method to manage the dependencies. The org.gradle.api.artifacts.dsl.ArtifactHandler returned by #getArtifacts() method to manage the artifacts. The org.gradle.api.artifacts.dsl.RepositoryHandler returned by 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 which uniquely identifies it in the hierarchy.

Plugins

Plugins can be used to modularise and reuse project configuration. Plugins can be applied using the PluginAware#apply(java.util.Map) method, or by using the org.gradle.plugin.use.PluginDependenciesSpec plugins script block.

Properties

Gradle executes the project's build file against the Project instance to configure the project. Any property or method which your script uses is delegated through to the associated Project object. This means, that you can use any of the methods and properties on the Project 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 the Project instance using the project property. This can make the script clearer in some cases. For example, you could use project.name rather than name to access the project's name.

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

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

When writing a property, the project searches the above scopes in order, and sets the property in the first scope it finds the property in. If not found, an exception is thrown. See #setProperty(String, 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 can be 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:

Properties

DEFAULT_BUILD_DIR_NAME

static val DEFAULT_BUILD_DIR_NAME: String

The default build directory name.

DEFAULT_BUILD_FILE

static val DEFAULT_BUILD_FILE: String

The default project build file name.

DEFAULT_STATUS

static val DEFAULT_STATUS: String

DEFAULT_VERSION

static val DEFAULT_VERSION: String

GRADLE_PROPERTIES

static val GRADLE_PROPERTIES: String

PATH_SEPARATOR

static val PATH_SEPARATOR: String

The hierarchy separator for project and task path names.

SYSTEM_PROP_PREFIX

static val SYSTEM_PROP_PREFIX: String

Functions

absoluteProjectPath

abstract fun absoluteProjectPath(path: String): String

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

afterEvaluate

abstract fun afterEvaluate(action: Action<in Project>): Unit

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

abstract fun afterEvaluate(closure: Closure<Any>): Unit

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

allprojects

abstract fun allprojects(action: Action<in Project>): Unit

Configures this project and each of its sub-projects.

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

abstract fun allprojects(configureClosure: Closure<Any>): Unit

Configures this project and each of its sub-projects.

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

ant

abstract fun ant(configureClosure: Closure<Any>): AntBuilder

Executes the given closure against the AntBuilder for this project. You can use this in your build file to execute ant tasks. The AntBuild is passed to the closure as the closure's delegate. See example in javadoc for #getAnt()

abstract fun ant(configureAction: Action<in AntBuilder>): AntBuilder

Executes the given action against the AntBuilder for this project. You can use this in your build file to execute ant tasks. See example in javadoc for #getAnt()

artifacts

abstract fun artifacts(configureClosure: Closure<Any>): Unit

Configures the published artifacts for this project.

This method executes the given closure against the ArtifactHandler for this project. The 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 configuration artifacts { //configuration name and the task: schema schemaJar } 

abstract fun artifacts(configureAction: Action<in ArtifactHandler>): Unit

Configures the published artifacts for this project.

This method executes the given action against the ArtifactHandler 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 configuration artifacts { //configuration name and the task: schema schemaJar } 

beforeEvaluate

abstract fun beforeEvaluate(action: Action<in Project>): Unit

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

abstract fun beforeEvaluate(closure: Closure<Any>): Unit

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

buildscript

abstract fun buildscript(configureClosure: Closure<Any>): Unit

Configures the build script classpath for this project.

The given closure is executed against this project's ScriptHandler. The ScriptHandler is passed to the closure as the closure's delegate.

configurations

abstract fun configurations(configureClosure: Closure<Any>): Unit

Configures the dependency configurations for this project.

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

Examples: See docs for ConfigurationContainer

configure

abstract fun configure(object: Any, configureClosure: Closure<Any>): Any

Configures an object via a closure, with the closure's delegate set to the supplied object. This way you don't have 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 if required:

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

abstract fun configure(objects: MutableIterable<*>, configureClosure: Closure<Any>): MutableIterable<*>

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

abstract fun <T : Any> configure(objects: MutableIterable<T>, configureAction: Action<in T>): MutableIterable<T>

Configures a collection of objects via an action.

container

abstract fun <T : Any> container(type: Class<T>): NamedDomainObjectContainer<T>

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 objects MUST expose their name as a bean property named "name". The name must be constant for the life of the object.

abstract fun <T : Any> container(type: Class<T>, factory: NamedDomainObjectFactory<T>): NamedDomainObjectContainer<T>

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

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

abstract fun <T : Any> container(type: Class<T>, factoryClosure: Closure<Any>): NamedDomainObjectContainer<T>

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 to the closure.

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

copy

abstract fun copy(closure: Closure<Any>): WorkResult

Copies the specified files. The given closure is used to configure a CopySpec, which is then used to copy the files. Example:

 copy { from configurations.runtime 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' } } 

abstract fun copy(action: Action<in CopySpec>): WorkResult

Copies the specified files. The given action is used to configure a CopySpec, which is then used to copy the files.

copySpec

abstract fun copySpec(closure: Closure<Any>): CopySpec

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

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

abstract fun copySpec(action: Action<in CopySpec>): CopySpec

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

abstract fun copySpec(): CopySpec

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

createAntBuilder

abstract fun createAntBuilder(): AntBuilder

Creates an additional AntBuilder for this project. You can use this in your build file to execute ant tasks.

defaultTasks

abstract fun defaultTasks(vararg defaultTasks: String): Unit

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

delete

abstract fun delete(vararg paths: Any): Boolean

Deletes files and directories.

This will not follow symlinks. If you need to follow symlinks too use #delete(Action).

abstract fun delete(action: Action<in DeleteSpec>): WorkResult

Deletes the specified files. The given action is used to configure a DeleteSpec, which is then used to delete the files.

Example:

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

dependencies

abstract fun dependencies(configureClosure: Closure<Any>): Unit

Configures the dependencies for this project.

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

Examples: See docs for DependencyHandler

dependencyLocking

abstract fun dependencyLocking(configuration: Action<in DependencyLockingHandler>): Unit

Configures dependency locking

depthCompare

abstract fun depthCompare(otherProject: Project): Int

Compares the nesting level of this project with another project of the multi-project hierarchy.

evaluationDependsOn

abstract fun evaluationDependsOn(path: String): Project

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

evaluationDependsOnChildren

abstract fun evaluationDependsOnChildren(): Unit

Declares that this project has an evaluation dependency on each of its child projects.

exec

abstract fun exec(closure: Closure<Any>): ExecResult

Executes an external command. The closure configures a org.gradle.process.ExecSpec.

abstract fun exec(action: Action<in ExecSpec>): ExecResult

Executes an external command.

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

file

abstract fun file(path: Any): File

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

  • A CharSequence, including String or groovy.lang.GString. Interpreted relative to the project directory. A string that starts with file: is treated as a file URL.
  • A File. If the file is an absolute file, it is returned as is. Otherwise, the file's path is interpreted relative to the project directory.
  • A java.nio.file.Path. The path must be associated with the default provider and is treated the same way as an instance of File.
  • A java.net.URI or java.net.URL. The URL's path is interpreted as the file path. Only file: URLs are supported.
  • A org.gradle.api.file.Directory or org.gradle.api.file.RegularFile.
  • A Provider of any supported type. The provider's value is resolved recursively.
  • A Closure that returns any supported type. The closure's return value is resolved recursively.
  • A java.util.concurrent.Callable that returns any supported type. The callable's return value is resolved recursively.

abstract fun file(path: Any, validation: PathValidation): File

Resolves a file path relative to the project directory of this project and validates it using the given scheme. See PathValidation for the list of possible validations.

fileTree

abstract fun fileTree(baseDir: Any): ConfigurableFileTree

Creates a new ConfigurableFileTree using the given base directory. The given baseDir path is evaluated as per #file(Object).

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

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

abstract fun fileTree(baseDir: Any, configureClosure: Closure<Any>): ConfigurableFileTree

Creates a new ConfigurableFileTree using the given base directory. The given baseDir path is evaluated as per #file(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 are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.

abstract fun fileTree(baseDir: Any, configureAction: Action<in ConfigurableFileTree>): ConfigurableFileTree

Creates a new ConfigurableFileTree using the given base directory. The given baseDir path is evaluated as per #file(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 are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.

abstract fun fileTree(args: MutableMap<String, *>): ConfigurableFileTree

Creates a new ConfigurableFileTree using the provided map of arguments. The map will be applied as properties 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 are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.

files

abstract fun files(vararg paths: Any): ConfigurableFileCollection

Returns a ConfigurableFileCollection containing the given files. You can pass any of the following types to this method:

  • A CharSequence, including String or groovy.lang.GString. Interpreted relative to the project directory, as per #file(Object). A string that starts with file: is treated as a file URL.
  • A File. Interpreted relative to the project directory, as per #file(Object).
  • A java.nio.file.Path as defined by #file(Object).
  • A java.net.URI or java.net.URL. The URL's path is interpreted as a file path. Only file: URLs are supported.
  • A org.gradle.api.file.Directory or org.gradle.api.file.RegularFile.
  • A java.util.Collection, Iterable, or an array that contains objects of any supported type. The elements of the collection are recursively converted to files.
  • A org.gradle.api.file.FileCollection. The contents of the collection are included in the returned collection.
  • A Provider 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.
  • A java.util.concurrent.Callable that returns any supported type. The return value of the call() method is recursively converted to files. A null return value is treated as an empty collection.
  • A Closure that returns any of the types listed here. The return value of the closure is recursively converted to files. A null return value is treated as an empty collection.
  • A Task. Converted to the task's output files. The task is executed if the file collection is used as an input to another task.
  • A org.gradle.api.tasks.TaskOutputs. 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 a failure.

The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of 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.

abstract fun files(paths: Any, configureClosure: Closure<Any>): ConfigurableFileCollection

Creates a new ConfigurableFileCollection using the given paths. The paths are evaluated as per . The file collection is configured using the given closure. The file collection is passed to the 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 file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.

abstract fun files(paths: Any, configureAction: Action<in ConfigurableFileCollection>): ConfigurableFileCollection

Creates a new ConfigurableFileCollection using the given paths. The paths are evaluated as per . 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 file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.

findProject

abstract fun findProject(path: String): Project

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

findProperty

abstract fun findProperty(propertyName: String): Any

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 the property.
  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 the given name.
  7. If not found, null value is returned.

getAllTasks

abstract fun getAllTasks(recursive: Boolean): MutableMap<Project, MutableSet<Task>>

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

getAllprojects

abstract fun getAllprojects(): MutableSet<Project>

Returns the set containing this project and its subprojects.

getAnt

abstract fun getAnt(): AntBuilder

Returns the AntBuilder for this project. You can use this in your build file to execute ant tasks. 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") } } 

getArtifacts

abstract fun getArtifacts(): ArtifactHandler

Returns a handler for assigning artifacts produced by the project to configurations. Examples:See docs for ArtifactHandler

getBuildDir

abstract fun getBuildDir(): File

Returns the build directory of this project. The build directory is the directory which all artifacts are generated into. The default value for the build directory is projectDir/build

getBuildFile

abstract fun getBuildFile(): File

The build script for this project.

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

getBuildscript

abstract fun getBuildscript(): ScriptHandler

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

getChildProjects

abstract fun getChildProjects(): MutableMap<String, Project>

Returns the direct children of this project.

getComponents

abstract fun getComponents(): SoftwareComponentContainer

Returns the software components produced by this project.

getConfigurations

abstract fun getConfigurations(): ConfigurationContainer

Returns the configurations of this project. Examples: See docs for ConfigurationContainer

getConvention

abstract fun getConvention(): Convention

Returns the Convention for this project.

You can access this property in your build file using convention. You can also access the properties and methods of the convention object as if they were properties and methods of this project. See here for more details

getDefaultTasks

abstract fun getDefaultTasks(): MutableList<String>

Returns the names of the default tasks of this project. These are used when no tasks names are provided when starting the build.

getDependencies

abstract fun getDependencies(): DependencyHandler

Returns the dependency handler of this project. The returned dependency handler instance can be used for adding new dependencies. For accessing already declared dependencies, the configurations can be used. Examples: See docs for DependencyHandler

getDependencyLocking

abstract fun getDependencyLocking(): DependencyLockingHandler

Provides access to configuring dependency locking

getDepth

abstract fun getDepth(): Int

Returns the nesting level of a project in a multi-project hierarchy. For single project builds this is always 0. In a multi-project hierarchy 0 is returned for the root project.

getDescription

abstract fun getDescription(): String

Returns the description of this project, if any.

getDisplayName

abstract fun getDisplayName(): String

Returns a human-consumable display name for this project.

getExtensions

abstract fun getExtensions(): ExtensionContainer

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

getGradle

abstract fun getGradle(): Gradle

Returns the org.gradle.api.invocation.Gradle invocation which this project belongs to.

getGroup

abstract fun getGroup(): Any

Returns the group of this project. Gradle always uses the toString() value of the group. The group defaults to the path with dots as separators.

getLayout

abstract fun getLayout(): ProjectLayout

Provides access to various important directories for this project.

getLogger

abstract fun getLogger(): Logger

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

getLogging

abstract fun getLogging(): LoggingManager

Returns the org.gradle.api.logging.LoggingManager which can be used to receive logging and to control the standard output/error capture for this project's build script. By default, System.out is redirected to the Gradle logging system at the QUIET log level, and System.err is redirected at the ERROR log level.

getName

abstract fun getName(): String

Returns the name of this project. The project's name is not necessarily unique within a project hierarchy. You should use the #getPath() method for a unique identifier for the project.

getNormalization

abstract fun getNormalization(): InputNormalizationHandler

Provides access to configuring input normalization.

getObjects

abstract fun getObjects(): ObjectFactory

Provides access to methods to create various kinds of model objects.

getParent

abstract fun getParent(): Project

Returns the parent project of this project, if any.

getPath

abstract fun getPath(): String

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

getProject

abstract fun getProject(): Project

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

getProjectDir

abstract fun getProjectDir(): File

The directory containing the project build file.

getProperties

abstract fun getProperties(): MutableMap<String, *>

Returns the properties of this project. See here for details of the properties which are available for a project.

getProviders

abstract fun getProviders(): ProviderFactory

Provides access to methods to create various kinds of Provider instances.

getRepositories

abstract fun getRepositories(): RepositoryHandler

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

getResources

abstract fun getResources(): ResourceHandler

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

getRootDir

abstract fun getRootDir(): File

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

getRootProject

abstract fun getRootProject(): Project

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

getState

abstract fun getState(): ProjectState

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

getStatus

abstract fun getStatus(): Any

Returns the status of this project. Gradle always uses the toString() value of the status. The status defaults to {@value #DEFAULT_STATUS}.

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

getSubprojects

abstract fun getSubprojects(): MutableSet<Project>

Returns the set containing the subprojects of this project.

getTasks

abstract fun getTasks(): TaskContainer

Returns the tasks of this project.

getTasksByName

abstract fun getTasksByName(name: String, recursive: Boolean): MutableSet<Task>

Returns the set of tasks with the given name contained in this project, and optionally its subprojects.

getVersion

abstract fun getVersion(): Any

Returns the version of this project. Gradle always uses the toString() value of the version. The version defaults to {@value #DEFAULT_VERSION}.

hasProperty

abstract fun hasProperty(propertyName: String): Boolean

Determines if this project has the given property. See here for details of the properties which are available for a project.

javaexec

abstract fun javaexec(closure: Closure<Any>): ExecResult

Executes a Java main class. The closure configures a org.gradle.process.JavaExecSpec.

abstract fun javaexec(action: Action<in JavaExecSpec>): ExecResult

Executes an external Java process.

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

mkdir

abstract fun mkdir(path: Any): File

Creates a directory and returns a file pointing to it.

normalization

abstract fun normalization(configuration: Action<in InputNormalizationHandler>): Unit

Configures input normalization.

project

abstract fun project(path: String): Project

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

abstract fun project(path: String, configureClosure: Closure<Any>): Project

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

abstract fun project(path: String, configureAction: Action<in Project>): Project

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

property

abstract fun <T : Any> property(clazz: Class<T>): PropertyState<T>

Creates a PropertyState implementation based on the provided class.

abstract fun property(propertyName: String): Any

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 the property.
  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 the given name.
  7. If not found, a MissingPropertyException is thrown.

provider

abstract fun <T : Any> provider(value: Callable<T>): Provider<T>

Creates a Provider implementation based on the provided value.

relativePath

abstract fun relativePath(path: Any): String

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

relativeProjectPath

abstract fun relativeProjectPath(path: String): String

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

repositories

abstract fun repositories(configureClosure: Closure<Any>): Unit

Configures the repositories for this project.

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

setBuildDir

abstract fun setBuildDir(path: File): Unit

Sets the build directory of this project. The build directory is the directory which all artifacts are generated into.

abstract fun setBuildDir(path: Any): Unit

Sets the build directory of this project. The build directory is the directory which all artifacts are generated into. The path parameter is evaluated as described for #file(Object). This mean you can use, amongst other things, a relative or absolute path or File object to specify the build directory.

setDefaultTasks

abstract fun setDefaultTasks(defaultTasks: MutableList<String>): Unit

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

setDescription

abstract fun setDescription(description: String): Unit

Sets a description for this project.

setGroup

abstract fun setGroup(group: Any): Unit

Sets the group of this project.

setProperty

abstract fun setProperty(name: String, value: Any): Unit

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

  1. The project object itself. For example, the rootDir project property.
  2. The project's Convention object. For example, the srcRootName java plugin property.
  3. The project's extra properties.
If the property is not found, a groovy.lang.MissingPropertyException is thrown.

setStatus

abstract fun setStatus(status: Any): Unit

Sets the status of this project.

setVersion

abstract fun setVersion(version: Any): Unit

Sets the version of this project.

subprojects

abstract fun subprojects(action: Action<in Project>): Unit

Configures the sub-projects of this project

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

abstract fun subprojects(configureClosure: Closure<Any>): Unit

Configures the sub-projects of this project.

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

sync

abstract fun sync(action: Action<in CopySpec>): WorkResult

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

This method is like the #copy(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' } } 

tarTree

abstract fun tarTree(tarPath: Any): FileTree

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

  • an instance of org.gradle.api.resources.Resource
  • any other object is evaluated as per #file(Object)
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.

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 the #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' } 

task

abstract fun task(name: String): Task

Creates a Task with the given name and adds it to this project. Calling this method is equivalent to calling #task(java.util.Map, 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 can reference the task by name in your build file. See here for more details

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

abstract fun task(args: MutableMap<String, *>, name: String): Task

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

OptionDescriptionDefault Value {@value org.gradle.api.Task#TASK_TYPE}The class of the task to create.org.gradle.api.DefaultTask {@value org.gradle.api.Task#TASK_OVERWRITE}Replace an existing task?false {@value org.gradle.api.Task#TASK_DEPENDS_ON}A task name or set of task names which this task depends on[] {@value org.gradle.api.Task#TASK_ACTION}A closure or Action to add to the task.null {@value org.gradle.api.Task#TASK_DESCRIPTION}A description of the task. null {@value org.gradle.api.Task#TASK_GROUP}A 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 can reference the task by name in your build file. See here for more details

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

abstract fun task(args: MutableMap<String, *>, name: String, configureClosure: Closure<Any>): Task

Creates a Task with the given name and adds it to this project. Before the task is returned, the given closure is executed to configure the task. A map of creation options can be passed to this method to control how the task is created. See #task(java.util.Map, 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 can reference the task by name in your build file. See here for more details

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

abstract fun task(name: String, configureClosure: Closure<Any>): Task

Creates a Task with the given name and adds it to this project. Before the task is returned, the given closure is executed to configure the task.

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

uri

abstract fun uri(path: Any): URI

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

zipTree

abstract fun zipTree(zipPath: Any): FileTree

Creates a new FileTree which contains the contents of the given ZIP file. The given zipPath path is evaluated as per #file(Object). You can combine this method with the #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 are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.

Inherited Functions

apply

abstract fun apply(closure: Closure<Any>): Unit
abstract fun apply(action: Action<in ObjectConfigurationAction>): Unit

Applies zero or more plugins or scripts.

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

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

abstract fun apply(options: MutableMap<String, *>): Unit

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 created ObjectConfigurationAction. That is, each key in the map is expected to be the name of a method ObjectConfigurationAction and the value to be compatible arguments to that method.

The following options are available:

  • from: A script to apply. Accepts any path supported by org.gradle.api.Project#uri(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.

getPluginManager

abstract fun getPluginManager(): PluginManager

The plugin manager for this plugin aware object.

getPlugins

abstract fun getPlugins(): PluginContainer

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 the plugin manager than use the plugin container.

Use one of the 'apply' methods on this interface or on the plugin manager to apply plugins instead of applying via the plugin container.

Use PluginManager#hasPlugin(String) or similar to query for the application of plugins instead of doing so via the plugin container.

Extension Properties

announce

val Project.announce: AnnouncePluginExtension

Retrieves the announce extension.

application

val Project.application: ApplicationPluginConvention

Retrieves the application convention.

base

val Project.base: BasePluginConvention

Retrieves the base convention.

buildTypes

val Project.buildTypes: BuildTypeContainer

Retrieves the buildTypes extension.

checkstyle

val Project.checkstyle: CheckstyleExtension

Retrieves the checkstyle extension.

codenarc

val Project.codenarc: CodeNarcExtension

Retrieves the codenarc extension.

defaultArtifacts

val Project.defaultArtifacts: <ERROR CLASS>

Retrieves the defaultArtifacts extension.

distributions

val Project.distributions: DistributionContainer

Retrieves the distributions extension.

ear

val Project.ear: EarPluginConvention

Retrieves the ear convention.

eclipse

val Project.eclipse: EclipseModel

Retrieves the eclipse extension.

ext

val Project.ext: ExtraPropertiesExtension

Retrieves the ext extension.

findbugs

val Project.findbugs: FindBugsExtension

Retrieves the findbugs extension.

flavors

val Project.flavors: FlavorContainer

Retrieves the flavors extension.

gradlePlugin

val Project.gradlePlugin: GradlePluginDevelopmentExtension

Retrieves the gradlePlugin extension.

groovyRuntime

val Project.groovyRuntime: GroovyRuntime

Retrieves the groovyRuntime extension.

idea

val Project.idea: IdeaModel

Retrieves the idea extension.

jacoco

val Project.jacoco: JacocoPluginExtension

Retrieves the jacoco extension.

java

val Project.java: JavaPluginConvention

Retrieves the java convention.

javaScript

val Project.javaScript: JavaScriptExtension

Retrieves the javaScript extension.

jdepend

val Project.jdepend: JDependExtension

Retrieves the jdepend extension.

maven

val Project.maven: MavenPluginConvention

Retrieves the maven convention.

osgi

val Project.osgi: OsgiPluginConvention

Retrieves the osgi convention.

platforms

val Project.platforms: PlatformContainer

Retrieves the platforms extension.

playConfigurations

val Project.playConfigurations: PlayPluginConfigurations

Retrieves the playConfigurations extension.

pmd

val Project.pmd: PmdExtension

Retrieves the pmd extension.

projectReports

val Project.projectReports: ProjectReportsPluginConvention

Retrieves the projectReports convention.

publishing

val Project.publishing: PublishingExtension

Retrieves the publishing extension.

reporting

val Project.reporting: ReportingExtension

Retrieves the reporting extension.

scalaRuntime

val Project.scalaRuntime: ScalaRuntime

Retrieves the scalaRuntime extension.

signing

val Project.signing: SigningExtension

Retrieves the signing extension.

toolChains

val Project.toolChains: NativeToolChainRegistry

Retrieves the toolChains extension.

visualStudio

val Project.visualStudio: VisualStudioRootExtension

Retrieves the visualStudio extension.

war

val Project.war: WarPluginConvention

Retrieves the war convention.

xcode

val Project.xcode: XcodeRootExtension

Retrieves the xcode extension.

Extension Functions

announce

fun Project.announce(configure: AnnouncePluginExtension.() -> Unit): Unit

Configures the announce extension.

application

fun Project.application(configure: ApplicationPluginConvention.() -> Unit): Unit

Configures the application convention.

apply

fun <T : Plugin<Project>> Project.apply(): Unit

Applies the plugin of the given type T. Does nothing if the plugin has already been applied.

base

fun Project.base(configure: BasePluginConvention.() -> Unit): Unit

Configures the base convention.

buildTypes

fun Project.buildTypes(configure: BuildTypeContainer.() -> Unit): Unit

Configures the buildTypes extension.

buildscript

fun Project.buildscript(action: ScriptHandlerScope.() -> Unit): Unit

checkstyle

fun Project.checkstyle(configure: CheckstyleExtension.() -> Unit): Unit

Configures the checkstyle extension.

codenarc

fun Project.codenarc(configure: CodeNarcExtension.() -> Unit): Unit

Configures the codenarc extension.

configure

fun <T : Any> Project.configure(configuration: T.() -> Unit): Unit

Executes the given configuration block against the plugin convention or extension of the specified type.

createTask

fun <T : Task> Project.createTask(name: String, type: KClass<T>, configuration: T.() -> Unit): T

defaultArtifacts

fun Project.defaultArtifacts(configure: <ERROR CLASS>.() -> Unit): Unit

Configures the defaultArtifacts extension.

defaultTasks

fun Project.defaultTasks(vararg tasks: Task): Unit

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

dependencies

fun Project.dependencies(configuration: DependencyHandlerScope.() -> Unit): Unit

Configures the dependencies for this project.

distributions

fun Project.distributions(configure: DistributionContainer.() -> Unit): Unit

Configures the distributions extension.

ear

fun Project.ear(configure: EarPluginConvention.() -> Unit): Unit

Configures the ear convention.

eclipse

fun Project.eclipse(configure: EclipseModel.() -> Unit): Unit

Configures the eclipse extension.

ext

fun Project.ext(configure: ExtraPropertiesExtension.() -> Unit): Unit

Configures the ext extension.

findbugs

fun Project.findbugs(configure: FindBugsExtension.() -> Unit): Unit

Configures the findbugs extension.

flavors

fun Project.flavors(configure: FlavorContainer.() -> Unit): Unit

Configures the flavors extension.

gradleKotlinDsl

fun Project.gradleKotlinDsl(): Dependency

Creates a dependency on the API of the current version of the Gradle Kotlin DSL.

gradlePlugin

fun Project.gradlePlugin(configure: GradlePluginDevelopmentExtension.() -> Unit): Unit

Configures the gradlePlugin extension.

gradleScriptKotlinApi

fun Project.gradleScriptKotlinApi(): Dependency

groovyRuntime

fun Project.groovyRuntime(configure: GroovyRuntime.() -> Unit): Unit

Configures the groovyRuntime extension.

idea

fun Project.idea(configure: IdeaModel.() -> Unit): Unit

Configures the idea extension.

jacoco

fun Project.jacoco(configure: JacocoPluginExtension.() -> Unit): Unit

Configures the jacoco extension.

java

fun Project.java(configure: JavaPluginConvention.() -> Unit): Unit

Configures the java convention.

javaScript

fun Project.javaScript(configure: JavaScriptExtension.() -> Unit): Unit

Configures the javaScript extension.

jdepend

fun Project.jdepend(configure: JDependExtension.() -> Unit): Unit

Configures the jdepend extension.

maven

fun Project.maven(configure: MavenPluginConvention.() -> Unit): Unit

Configures the maven convention.

osgi

fun Project.osgi(configure: OsgiPluginConvention.() -> Unit): Unit

Configures the osgi convention.

platforms

fun Project.platforms(configure: PlatformContainer.() -> Unit): Unit

Configures the platforms extension.

playConfigurations

fun Project.playConfigurations(configure: PlayPluginConfigurations.() -> Unit): Unit

Configures the playConfigurations extension.

pmd

fun Project.pmd(configure: PmdExtension.() -> Unit): Unit

Configures the pmd extension.

projectReports

fun Project.projectReports(configure: ProjectReportsPluginConvention.() -> Unit): Unit

Configures the projectReports convention.

property

fun <T> Project.property(): PropertyState<T>

Creates a PropertyState that holds values of the given type T.

provideDelegate

operator fun Project.provideDelegate(any: Any?, property: KProperty<*>): PropertyDelegate

Locates a property on Project.

publishing

fun Project.publishing(configure: PublishingExtension.() -> Unit): Unit

Configures the publishing extension.

reporting

fun Project.reporting(configure: ReportingExtension.() -> Unit): Unit

Configures the reporting extension.

repositories

fun Project.repositories(configuration: RepositoryHandler.() -> Unit): Unit

Configures the repositories for this project.

scalaRuntime

fun Project.scalaRuntime(configure: ScalaRuntime.() -> Unit): Unit

Configures the scalaRuntime extension.

signing

fun Project.signing(configure: SigningExtension.() -> Unit): Unit

Configures the signing extension.

task

fun <type : Task> Project.task(name: String, configuration: type.() -> Unit): type

Creates a Task with the given name and type, configures it with the given configuration action, and adds it to this project tasks container.

fun <type : Task> Project.task(name: String): type

Creates a Task with the given name and type, and adds it to this project tasks container.

fun <T : Task> Project.task(name: String, type: KClass<T>, configuration: T.() -> Unit): Tfun Project.task(name: String, configuration: Task.() -> Unit): DefaultTask

Creates a Task with the given name and DefaultTask type, configures it with the given configuration action, and adds it to this project tasks container.

the

fun <T : Any> Project.the(): T
fun <T : Any> Project.the(extensionType: KClass<T>): T

Returns the plugin convention or extension of the specified type.

toolChains

fun Project.toolChains(configure: NativeToolChainRegistry.() -> Unit): Unit

Configures the toolChains extension.

visualStudio

fun Project.visualStudio(configure: VisualStudioRootExtension.() -> Unit): Unit

Configures the visualStudio extension.

war

fun Project.war(configure: WarPluginConvention.() -> Unit): Unit

Configures the war convention.

xcode

fun Project.xcode(configure: XcodeRootExtension.() -> Unit): Unit

Configures the xcode extension.

Inheritors

KotlinBuildScript

abstract class KotlinBuildScript : Project

Base class for Kotlin build scripts.