org.gradle.api
Interface Project

All Superinterfaces:
Comparable<Project>

public interface Project
extends Comparable<Project>

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 "build.gradle" 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 add() methods on TaskContainer, such as TaskContainer.add(String). You can locate existing tasks using one of the lookup methods on TaskContainer, such as 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 ConfigurationContainer returned by getConfigurations() ()} method to manage the configurations. The DependencyHandler returned by getDependencies() method to manage the dependencies. The ArtifactHandler returned by getArtifacts() ()} method to manage the artifacts. The RepositoryHandler returned by 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 which uniquely identifies it in the hierarchy.

Using a Project in a Build File

Gradle executes the project's build file against the Project instance to configure the project. Any property or method which your script uses which is not defined in the script 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()
 reportDir = file('reports') // Delegates to Project.file() and Project.setProperty()
 

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.

Dynamic Properties

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. 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, the project adds the property to its map of additional properties. See setProperty(String, Object) for more details.

Dynamic Methods

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


Field Summary
static String DEFAULT_BUILD_DIR_NAME
          The default build directory name.
static String DEFAULT_BUILD_FILE
          The default project build file name.
static String DEFAULT_STATUS
           
static String DEFAULT_VERSION
           
static String GRADLE_PROPERTIES
           
static String PATH_SEPARATOR
          The hierarchy separator for project and task path names.
static String SYSTEM_PROP_PREFIX
           
static String TMP_DIR_NAME
           
 
Method Summary
 String absolutePath(String path)
          Deprecated. Use absoluteProjectPath(String) instead.
 String absoluteProjectPath(String path)
          Converts a name to an absolute project path, resolving names relative to this project.
 void afterEvaluate(Action<? super Project> action)
          Adds an action to execute immediately after this project is evaluated.
 void afterEvaluate(Closure closure)
          Adds a closure to be called immediately after this project has been evaluated.
 void allprojects(Action<? super Project> action)
          Executes the given Action against this project and its subprojects.
 void allprojects(Closure configureClosure)
          Executes the given closure against this project and its sub-projects.
 AntBuilder ant(Closure configureClosure)
          Executes the given closure against the AntBuilder for this project.
 void apply(Closure closure)
          Configures this project using plugins or scripts.
 void apply(Map<String,?> options)
          Configures this project using plugins or scripts.
 void artifacts(Closure configureClosure)
          Configures the published artifacts for this project.
 void beforeEvaluate(Action<? super Project> action)
          Adds an action to execute immediately before this project is evaluated.
 void beforeEvaluate(Closure closure)
          Adds a closure to be called immediately before this project is evaluated.
 void buildscript(Closure configureClosure)
          Configures the build script classpath for this project.
 void captureStandardOutput(LogLevel level)
          Deprecated. Use the LoggingManager returned by getLogging() instead
 Project childrenDependOnMe()
          Declares that all child projects of this project have an execution dependency on this project.
 void configurations(Closure configureClosure)
          Configures the dependency configurations for this project.
 Iterable<?> configure(Iterable<?> objects, Closure configureClosure)
          Configures a collection of objects via a closure.
<T> Iterable<T>
configure(Iterable<T> objects, Action<? super T> configureAction)
          Configures a collection of objects via an action.
 Object configure(Object object, Closure configureClosure)
          Configures an object via a closure, with the closure's delegate set to the supplied object.
 WorkResult copy(Closure closure)
          Copy the specified files.
 CopySpec copySpec(Closure closure)
          Creates a CopySpec which can later be used to copy files or create an archive.
 AntBuilder createAntBuilder()
          Creates an additional AntBuilder for this project.
 RepositoryHandler createRepositoryHandler()
          Creates a new repository handler.
 Task createTask(Map<String,?> args, String name)
          Deprecated. You should use task(java.util.Map, String) instead.
 Task createTask(Map<String,?> args, String name, Action<? super Task> action)
          Deprecated. You should use task(java.util.Map, String) instead.
 Task createTask(Map<String,?> args, String name, Closure action)
          Deprecated. You should use task(java.util.Map, String) instead.
 Task createTask(String name)
          Deprecated. You should use task(String) instead.
 Task createTask(String name, Action<? super Task> action)
          Deprecated. You should use task(java.util.Map, String) instead.
 Task createTask(String name, Closure action)
          Deprecated. You should use task(java.util.Map, String) instead.
 void defaultTasks(String... defaultTasks)
          Sets the names of the default tasks of this project.
 boolean delete(Object... paths)
          Deletes files and directories.
 void dependencies(Closure configureClosure)
          Configures the dependencies for this project.
 void dependsOn(String path)
          Declares that this project has an execution dependency on the project with the given path.
 void dependsOn(String path, boolean evaluateDependsOnProject)
          Declares that this project has an execution dependency on the project with the given path.
 Project dependsOnChildren()
          Declares that this project have an execution dependency on each of its child projects.
 Project dependsOnChildren(boolean evaluateDependsOnProject)
          Declares that this project have an execution dependency on each of its child projects.
 int depthCompare(Project otherProject)
          Compares the nesting level of this project with another project of the multi-project hierarchy.
 void disableStandardOutputCapture()
          Deprecated. 
 Project evaluationDependsOn(String path)
          Declares that this project has an evaulation dependency on the project with the given path.
 ExecResult exec(Closure closure)
          Executes an external command.
 File file(Object path)
          Resolves a file path relative to the project directory of this project.
 File file(Object path, PathValidation validation)
          Resolves a file path relative to the project directory of this project and validates it using the given scheme.
 ConfigurableFileCollection files(Object... paths)
          Returns a ConfigurableFileCollection containing the given files.
 ConfigurableFileCollection files(Object paths, Closure configureClosure)
          Creates a new ConfigurableFileCollection using the given paths.
 ConfigurableFileTree fileTree(Closure closure)
          Creates a new ConfigurableFileTree using the provided closure.
 ConfigurableFileTree fileTree(Map<String,?> args)
          Creates a new ConfigurableFileTree using the provided map of arguments.
 ConfigurableFileTree fileTree(Object baseDir)
          Creates a new ConfigurableFileTree using the given base directory.
 Project findProject(String path)
          Locates a project by path.
 Set<Project> getAllprojects()
          Returns the set containing this project and its subprojects.
 Map<Project,Set<Task>> getAllTasks(boolean recursive)
          Returns a map of the tasks contained in this project, and optionally its subprojects.
 AntBuilder getAnt()
          Returns the AntBuilder for this project.
 ArtifactHandler getArtifacts()
          Returns a handler for assigning artifacts produced by the project to configurations.
 File getBuildDir()
          Returns the build directory of this project.
 String getBuildDirName()
          Deprecated. 
 File getBuildFile()
          Returns the build file Gradle will evaluate against this project object.
 ScriptHandler getBuildscript()
          Returns the build script handler for this project.
 Map<String,Project> getChildProjects()
          Returns the direct children of this project.
 ConfigurationContainer getConfigurations()
          Returns the configurations of this project.
 Convention getConvention()
          Return the Convention for this project.
 List<String> getDefaultTasks()
          Returns the names of the default tasks of this project.
 DependencyHandler getDependencies()
          Returns the dependency handler of this project.
 Set<Project> getDependsOnProjects()
          Returns the set of projects which this project depends on.
 int getDepth()
          Returns the nesting level of a project in a multi-project hierarchy.
 String getDescription()
          Returns the description of this project.
 Gradle getGradle()
          Returns the Gradle which this project belongs to.
 Object getGroup()
          Returns the group of this project.
 Logger getLogger()
          Returns the logger for this project.
 LoggingManager getLogging()
          Returns the LoggingManager which can be used to control the logging level and standard output/error capture for this project's build script.
 String getName()
          Returns the name of this project.
 Project getParent()
          Returns the parent project of this project, if any.
 String getPath()
          Returns the path of this project.
 PluginContainer getPlugins()
          Returns the plugins container for this project.
 Project getProject()
          Returns this project.
 File getProjectDir()
          The directory containing the project build file.
 Map<String,?> getProperties()
          Returns the properties of this project.
 RepositoryHandler getRepositories()
          Returns a handler to create repositories which are used for retrieving dependencies and uploading artifacts produced by the project.
 File getRootDir()
          Returns the root directory of this project.
 Project getRootProject()
          Returns the root project for the hierarchy that this project belongs to.
 ProjectState getState()
          Returns the evaluation state of this project.
 Object getStatus()
          Returns the status of this project.
 Set<Project> getSubprojects()
          Returns the set containing the subprojects of this project.
 TaskContainer getTasks()
          Returns the tasks of this project.
 Set<Task> getTasksByName(String name, boolean recursive)
          Returns the set of tasks with the given name contained in this project, and optionally its subprojects.
 Object getVersion()
          Returns the version of this project.
 boolean hasProperty(String propertyName)
          Determines if this project has the given property.
 ExecResult javaexec(Closure closure)
          Executes a Java main class.
 File mkdir(Object path)
          Creates a directory and returns a file pointing to it.
 Project project(String path)
          Locates a project by path.
 Project project(String path, Closure configureClosure)
          Locates a project by path and configures it using the given closure.
 Object property(String propertyName)
          Returns the value of the given property.
 String relativePath(Object path)
          Returns the relative path from the project directory to the given path.
 String relativeProjectPath(String path)
          Converts a name to a project path relative to this project.
 void repositories(Closure configureClosure)
          Configures the repositories for this project.
 void setBuildDir(Object path)
          Sets the build directory of this project.
 void setBuildDirName(String buildDirName)
          Deprecated. Use setBuildDir(Object) instead.
 void setDefaultTasks(List<String> defaultTasks)
          Sets the names of the default tasks of this project.
 void setDescription(String description)
          Sets a description for this project.
 void setProperty(String name, Object value)
          Sets a property of this project.
 void subprojects(Action<? super Project> action)
          Executes the given Action against the subprojects of this project.
 void subprojects(Closure configureClosure)
          Executes the given closure against each of the sub-projects of this project.
 FileTree tarTree(Object tarPath)
          Creates a new FileTree which contains the contents of the given TAR file.
 Task task(Map<String,?> args, String name)
          Creates a Task with the given name and adds it to this project.
 Task task(Map<String,?> args, String name, Closure configureClosure)
          Creates a Task with the given name and adds it to this project.
 Task task(String name)
          Creates a Task with the given name and adds it to this project.
 Task task(String name, Closure configureClosure)
          Creates a Task with the given name and adds it to this project.
 URI uri(Object path)
          Resolves a file path to a URI, relative to the project directory of this project.
 Project usePlugin(Class<? extends Plugin> pluginClass)
          Deprecated. You should use the apply(java.util.Map) or apply(groovy.lang.Closure) method instead.
 Project usePlugin(String pluginId)
          Deprecated. You should use the apply(java.util.Map) or apply(groovy.lang.Closure) method instead.
 FileTree zipTree(Object zipPath)
          Creates a new FileTree which contains the contents of the given ZIP file.
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

DEFAULT_BUILD_FILE

static final String DEFAULT_BUILD_FILE
The default project build file name.

See Also:
Constant Field Values

PATH_SEPARATOR

static final String PATH_SEPARATOR
The hierarchy separator for project and task path names.

See Also:
Constant Field Values

DEFAULT_BUILD_DIR_NAME

static final String DEFAULT_BUILD_DIR_NAME
The default build directory name.

See Also:
Constant Field Values

GRADLE_PROPERTIES

static final String GRADLE_PROPERTIES
See Also:
Constant Field Values

SYSTEM_PROP_PREFIX

static final String SYSTEM_PROP_PREFIX
See Also:
Constant Field Values

TMP_DIR_NAME

static final String TMP_DIR_NAME
See Also:
Constant Field Values

DEFAULT_VERSION

static final String DEFAULT_VERSION
See Also:
Constant Field Values

DEFAULT_STATUS

static final String DEFAULT_STATUS
See Also:
Constant Field Values
Method Detail

getRootProject

Project getRootProject()

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.

You can access this property in your build file using rootProject

Returns:
The root project. Never returns null.

getRootDir

File getRootDir()

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

You can access this property in your build file using rootDir

Returns:
The root directory. Never returns null.

getBuildDir

File getBuildDir()

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

You can access this property in your build file using buildDir

Returns:
The build directory. Never returns null.

setBuildDir

void setBuildDir(Object path)

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.

Parameters:
path - The build directory. This is evaluated as for file(Object)

getBuildDirName

@Deprecated
String getBuildDirName()
Deprecated. 

Returns the name of the build directory of this project. It is resolved relative to the project directory of this project to determine the build directory. The default value is "build".

You can access this property in your build file using buildDirName

Returns:
The build dir name. Never returns null.

setBuildDirName

@Deprecated
void setBuildDirName(String buildDirName)
Deprecated. Use setBuildDir(Object) instead.

Sets the build directory name of this project.

Parameters:
buildDirName - The build dir name. Should not be null.

getBuildFile

File getBuildFile()

Returns the build file Gradle will evaluate against this project object. The default is "build.gradle". If an embedded script is provided the build file will be null.

You can access this property in your build file using buildFile

Returns:
Current build file. May return null.

getParent

Project getParent()

Returns the parent project of this project, if any.

You can access this property in your build file using parent

Returns:
The parent project, or null if this is the root project.

getName

String getName()

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.

You can access this property in your build file using name

Returns:
The name of this project. Never return null.

getDescription

String getDescription()
Returns the description of this project.

Returns:
the description. May return null.

setDescription

void setDescription(String description)
Sets a description for this project.

Parameters:
description - The description of the project. Might be null.

getGroup

Object getGroup()

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

You can access this property in your build file using group

Returns:
The group of this project. Never returns null.

getVersion

Object getVersion()

Returns the version of this project. Gradle always uses the toString() value of a version. The version defaults to "unspecified".

You can access this property in your build file using version

Returns:
The version of this project. Never returns null.

getStatus

Object getStatus()

Returns the status of this project. Gradle always uses the toString() value of a version. The status defaults to "release".

You can access this property in your build file using 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.

Returns:
The status of this project. Never returns null.

getChildProjects

Map<String,Project> getChildProjects()

Returns the direct children of this project.

You can access this property in your build file using childProjects

Returns:
A map from child project name to child project. Returns an empty map if this this project does not have any children.

getDependsOnProjects

Set<Project> getDependsOnProjects()

Returns the set of projects which this project depends on.

You can access this property in your build file using dependsOnProjects

Returns:
The set of projects. Returns an empty set if this project depends on no projects.

setProperty

void setProperty(String name,
                 Object value)

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 additional properties.

If the property is not found in any of these locations, it is added to the project's additional properties.

Parameters:
name - The name of the property
value - The value of the property

getProject

Project getProject()

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.

You can access this property in your build file using project

Returns:
This project. Never returns null.

getAllprojects

Set<Project> getAllprojects()

Returns the set containing this project and its subprojects.

You can access this property in your build file using allprojects

Returns:
The set of projects.

getSubprojects

Set<Project> getSubprojects()

Returns the set containing the subprojects of this project.

You can access this property in your build file using subprojects

Returns:
The set of projects. Returns an empty set if this project has no subprojects.

usePlugin

@Deprecated
Project usePlugin(String pluginId)
Deprecated. You should use the apply(java.util.Map) or apply(groovy.lang.Closure) method instead.

Applies a Plugin to this project.

Parameters:
pluginId - The id of the plugin.
Returns:
This project.

usePlugin

@Deprecated
Project usePlugin(Class<? extends Plugin> pluginClass)
Deprecated. You should use the apply(java.util.Map) or apply(groovy.lang.Closure) method instead.

Applies a Plugin to this project.

Parameters:
pluginClass - The class of the plugin. This class must implement the Plugin interface.
Returns:
This project.

task

Task task(String name)
          throws InvalidUserDataException

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.

Parameters:
name - The name of the task to be created
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

task

Task task(Map<String,?> args,
          String name)
          throws InvalidUserDataException

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
"type"The class of the task to create.DefaultTask
"overwrite"Replace an existing task?false
"dependsOn"A task name or set of task names which this task depends on[]
"action"A closure or Action to add to the task.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.

Parameters:
args - The task creation options.
name - The name of the task to be created
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

task

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

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.

Parameters:
args - The task creation options.
name - The name of the task to be created
configureClosure - The closure to use to configure the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

task

Task task(String name,
          Closure configureClosure)

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

Parameters:
name - The name of the task to be created
configureClosure - The closure to use to configure the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

createTask

@Deprecated
Task createTask(String name)
                throws InvalidUserDataException
Deprecated. You should use task(String) instead.

Creates a Task with the given name and adds it to this project. Calling this method is equivalent to calling createTask(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.

Parameters:
name - The name of the task to be created
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

createTask

@Deprecated
Task createTask(String name,
                           Action<? super Task> action)
                throws InvalidUserDataException
Deprecated. You should use task(java.util.Map, String) instead.

Creates a Task with the given name and adds it to this project. Before the task is returned, the given action is passed to the task's Task.doFirst(Action) method. Calling this method is equivalent to calling createTask(java.util.Map, String, Action) 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.

Parameters:
name - The name of the task to be created
action - The action to be passed to the Task.doFirst(Action) method of the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

createTask

@Deprecated
Task createTask(Map<String,?> args,
                           String name)
                throws InvalidUserDataException
Deprecated. You should use task(java.util.Map, String) instead.

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
"type"The class of the task to create.DefaultTask
"overwrite"Replace an existing task?false
"dependsOn"A task name or set of task names which this task depends on[]

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.

Parameters:
args - The task creation options.
name - The name of the task to be created
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

createTask

@Deprecated
Task createTask(Map<String,?> args,
                           String name,
                           Action<? super Task> action)
                throws InvalidUserDataException
Deprecated. You should use task(java.util.Map, String) instead.

Creates a Task with the given name and adds it to this project. Before the task is returned, the given action is passed to the task's Task.doFirst(Action) method. A map of creation options can be passed to this method to control how the task is created. See createTask(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.

Parameters:
args - The task creation options.
name - The name of the task to be created
action - The action to be passed to the Task.doFirst(Action) method of the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

createTask

@Deprecated
Task createTask(String name,
                           Closure action)
Deprecated. You should use task(java.util.Map, String) instead.

Creates a Task with the given name and adds it to this project. Before the task is returned, the given action closure is passed to the task's Task.doFirst(Closure) method. Calling this method is equivalent to calling createTask(java.util.Map, String, Closure) 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.

Parameters:
name - The name of the task to be created
action - The closure to be passed to the Task.doFirst(Closure) method of the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

createTask

@Deprecated
Task createTask(Map<String,?> args,
                           String name,
                           Closure action)
Deprecated. You should use task(java.util.Map, String) instead.

Creates a Task with the given name and adds it to this project. Before the task is returned, the given action closure is passed to the task's Task.doFirst(Closure) method. A map of creation options can be passed to this method to control how the task is created. See createTask(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.

Parameters:
args - The task creation options.
name - The name of the task to be created
action - The closure to be passed to the Task.doFirst(Closure) method of the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exists in this project.

getPath

String getPath()

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

Returns:
The path. Never returns null.

getDefaultTasks

List<String> getDefaultTasks()

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

Returns:
The default task names. Returns an empty list if this project has no default tasks.

setDefaultTasks

void setDefaultTasks(List<String> defaultTasks)

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

Parameters:
defaultTasks - The default task names.

defaultTasks

void defaultTasks(String... defaultTasks)

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

Parameters:
defaultTasks - The default task names.

dependsOn

void dependsOn(String path)
               throws UnknownProjectException

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

Parameters:
path - The path of the project which this project depends on.
Throws:
UnknownProjectException - If no project with the given path exists.

dependsOn

void dependsOn(String path,
               boolean evaluateDependsOnProject)
               throws UnknownProjectException

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

Parameters:
path - The path of the project which this project depends on.
evaluateDependsOnProject - If true, adds an evaluation dependency.
Throws:
UnknownProjectException - If no project with the given path exists.

evaluationDependsOn

Project evaluationDependsOn(String path)
                            throws UnknownProjectException

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

Parameters:
path - The path of the project which this project depends on.
Returns:
The project which this project depends on.
Throws:
UnknownProjectException - If no project with the given path exists.

childrenDependOnMe

Project childrenDependOnMe()

Declares that all child projects of this project have an execution dependency on this project.

Returns:
this project.

dependsOnChildren

Project dependsOnChildren()

Declares that this project have an execution dependency on each of its child projects.

Returns:
this project.

dependsOnChildren

Project dependsOnChildren(boolean evaluateDependsOnProject)

Declares that this project have an execution dependency on each of its child projects.

Parameters:
evaluateDependsOnProject - If true, adds an evaluation dependency.
Returns:
this project.

findProject

Project findProject(String path)

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

Parameters:
path - The path.
Returns:
The project with the given path. Returns null if no such project exists.

project

Project project(String path)
                throws UnknownProjectException

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

Parameters:
path - The path.
Returns:
The project with the given path. Never returns null.
Throws:
UnknownProjectException - If no project with the given path exists.

project

Project project(String path,
                Closure configureClosure)

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.

Parameters:
path - The path.
configureClosure - The closure to use to configure the project.
Returns:
The project with the given path. Never returns null.
Throws:
UnknownProjectException - If no project with the given path exists.

getAllTasks

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

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

Parameters:
recursive - If true, returns the tasks of this project and its subprojects. If false, returns the tasks of just this project.
Returns:
A map from project to a set of tasks.

getTasksByName

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

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

Parameters:
name - The name of the task to locate.
recursive - If true, returns the tasks of this project and its subprojects. If false, returns the tasks of just this project.
Returns:
The set of tasks. Returns an empty set if no such tasks exist in this project.

getProjectDir

File getProjectDir()

The directory containing the project build file.

You can access this property in your build file using projectDir

Returns:
The project directory. Never returns null.

file

File file(Object path)

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

Parameters:
path - The object to resolve as a File.
Returns:
The resolved file. Never returns null.

file

File file(Object path,
          PathValidation validation)
          throws InvalidUserDataException

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.

Parameters:
path - An object which toString method value is interpreted as a relative path to the project directory.
validation - The validation to perform on the file.
Returns:
The resolved file. Never returns null.
Throws:
InvalidUserDataException - When the file does not meet the given validation constraint.

uri

URI uri(Object path)

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.

Parameters:
path - The object to resolve as a URI.
Returns:
The resolved URI. Never returns null.

relativePath

String relativePath(Object path)

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.

Parameters:
path - The path to convert to a relative path.
Returns:
The relative path. Never returns null.

files

ConfigurableFileCollection files(Object... paths)

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

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.

Parameters:
paths - The paths to the files. May be empty.
Returns:
The file collection. Never returns null.

files

ConfigurableFileCollection files(Object paths,
                                 Closure configureClosure)

Creates a new ConfigurableFileCollection using the given paths. The paths are evaluated as for files(Object...). 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.

Parameters:
paths - The contents of the file collection. Evaluated as for files(Object...).
configureClosure - The closure to use to configure the file collection.
Returns:
the configured file tree. Never returns null.

fileTree

ConfigurableFileTree fileTree(Object baseDir)

Creates a new ConfigurableFileTree using the given base directory. The given baseDir path is evaluated as for 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.

Parameters:
baseDir - The base directory of the file tree. Evaluated as for file(Object).
Returns:
the file tree. Never returns null.

fileTree

ConfigurableFileTree fileTree(Map<String,?> args)

Creates a new ConfigurableFileTree using the provided map of arguments. The map will be applied as properties on the new file tree. Example:

 fileTree(dir:'src', excludes:['**/ignore/**','**/.svn/**'])
 

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.

Parameters:
args - map of property assignments to ConfigurableFileTree object
Returns:
the configured file tree. Never returns null.

fileTree

ConfigurableFileTree fileTree(Closure closure)

Creates a new ConfigurableFileTree using the provided closure. The closure will be used to configure the new file tree. The file tree is passed to the closure as its delegate. Example:

 fileTree {
    from 'src'
    exclude '**/.svn/**'
 }.copy { into 'dest'}
 

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.

Parameters:
closure - Closure to configure the ConfigurableFileTree object
Returns:
the configured file tree. Never returns null.

zipTree

FileTree zipTree(Object zipPath)

Creates a new FileTree which contains the contents of the given ZIP file. The given zipPath path is evaluated as for 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.

Parameters:
zipPath - The ZIP file. Evaluated as for file(Object).
Returns:
the file tree. Never returns null.

tarTree

FileTree tarTree(Object tarPath)

Creates a new FileTree which contains the contents of the given TAR file. The given tarPath path is evaluated as for file(Object). You can combine this method with the copy(groovy.lang.Closure) method to untar a TAR 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.

Parameters:
tarPath - The TAR file. Evaluated as for file(Object).
Returns:
the file tree. Never returns null.

mkdir

File mkdir(Object path)
Creates a directory and returns a file pointing to it.

Parameters:
path - The path for the directory to be created. Evaluated as for file(Object).
Returns:
the created directory
Throws:
InvalidUserDataException - If the path points to an existing file.

delete

boolean delete(Object... paths)
Deletes files and directories.

Parameters:
paths - Any type of object accepted by files(Object...)
Returns:
true if anything got deleted, false otherwise

javaexec

ExecResult javaexec(Closure closure)
Executes a Java main class. The closure configures a JavaExecSpec.

Parameters:
closure - The closure for configuring the execution.
Returns:
the result of the execution

exec

ExecResult exec(Closure closure)
Executes an external command. The closure configures a ExecSpec.

Parameters:
closure - The closure for configuring the execution.
Returns:
the result of the execution

absolutePath

@Deprecated
String absolutePath(String path)
Deprecated. Use absoluteProjectPath(String) instead.

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

Parameters:
path - The path to convert.
Returns:
The absolute path.

absoluteProjectPath

String absoluteProjectPath(String path)

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

Parameters:
path - The path to convert.
Returns:
The absolute path.

relativeProjectPath

String relativeProjectPath(String path)

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

Parameters:
path - The path to convert.
Returns:
The relative path.

getAnt

AntBuilder getAnt()

Returns the AntBuilder for this project. You can use this in your build file to execute ant tasks.

You can access this property in your build file using ant

Returns:
The AntBuilder for this project. Never returns null.

createAntBuilder

AntBuilder createAntBuilder()

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

Returns:
Creates an AntBuilder for this project. Never returns null.
See Also:
getAnt()

ant

AntBuilder ant(Closure configureClosure)

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.

You can call this method in your build file using ant followed by a code block.

Parameters:
configureClosure - The closure to execute against the AntBuilder.
Returns:
The AntBuilder. Never returns null.

getConfigurations

ConfigurationContainer getConfigurations()
Returns the configurations of this project.

Returns:
The configuration of this project.

configurations

void configurations(Closure configureClosure)
Configures the dependency configurations for this project. Executes the given closure against the ConfigurationContainer for this project. The ConfigurationContainer is passed to the closure as the closure's delegate.

Parameters:
configureClosure - the closure to use to configure the dependency configurations.

getArtifacts

ArtifactHandler getArtifacts()
Returns a handler for assigning artifacts produced by the project to configurations.


artifacts

void artifacts(Closure configureClosure)
Configures the published artifacts for this project. Executes the given closure against the ArtifactHandler for this project. The ArtifactHandler is passed to the closure as the closure's delegate.

Parameters:
configureClosure - the closure to use to configure the published artifacts.

getConvention

Convention getConvention()

Return the Convention for this project.

You can access this property in your build file using convention. You can also 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

Returns:
The Convention. Never returns null.

depthCompare

int depthCompare(Project otherProject)

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

Parameters:
otherProject - The project to compare the nesting level with.
Returns:
a negative integer, zero, or a positive integer as this project has a nesting level less than, equal to, or greater than the specified object.
See Also:
getDepth()

getDepth

int getDepth()

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.


getTasks

TaskContainer getTasks()

Returns the tasks of this project.

Returns:
the tasks of this project.

subprojects

void subprojects(Action<? super Project> action)

Executes the given Action against the subprojects of this project.

Parameters:
action - The action to execute.

subprojects

void subprojects(Closure configureClosure)

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

You can call this method in your build file using subprojects followed by a code block.

Parameters:
configureClosure - The closure to execute. The closure receives no parameters.

allprojects

void allprojects(Action<? super Project> action)

Executes the given Action against this project and its subprojects.

Parameters:
action - The action to execute.

allprojects

void allprojects(Closure configureClosure)

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

You can call this method in your build file using allprojects followed by a code block.

Parameters:
configureClosure - The closure to execute. The closure receives no parameters.

beforeEvaluate

void beforeEvaluate(Action<? super Project> action)
Adds an action to execute immediately before this project is evaluated.

Parameters:
action - the action to execute.

afterEvaluate

void afterEvaluate(Action<? super Project> action)
Adds an action to execute immediately after this project is evaluated.

Parameters:
action - the action to execute.

beforeEvaluate

void beforeEvaluate(Closure closure)

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

Parameters:
closure - The closure to call.

afterEvaluate

void afterEvaluate(Closure closure)

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 futher configure those child projects based on the state of the child projects after their build files have been run.

Parameters:
closure - The closure to call.

hasProperty

boolean hasProperty(String propertyName)

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

Parameters:
propertyName - The name of the property to locate.
Returns:
True if this project has the given property, false otherwise.

getProperties

Map<String,?> getProperties()

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

Returns:
A map from property name to value.

property

Object property(String propertyName)
                throws MissingPropertyException

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's convention object has a property with the given name, return the value of the property.
  3. If this project has an additional property with the given name, return the value of the property.
  4. If this project has a task with the given name, return the task.
  5. Search up through this project's ancestor projects for a convention property or additional property with the given name.
  6. If not found, throw MissingPropertyException

Parameters:
propertyName - The name of the property.
Returns:
The value of the property, possibly null.
Throws:
MissingPropertyException - When the given property is unknown.

getLogger

Logger getLogger()

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

You can use this property in your build file using logger.

Returns:
The logger. Never returns null.

getGradle

Gradle getGradle()

Returns the Gradle which this project belongs to.

You can use this property in your build file using gradle.

Returns:
The Gradle object. Never returns null.

getLogging

LoggingManager getLogging()
Returns the LoggingManager which can be used to control the logging level and 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.

Returns:
the LoggingManager. Never returns null.

disableStandardOutputCapture

@Deprecated
void disableStandardOutputCapture()
Deprecated. 

Disables redirection of standard output during project evaluation. By default redirection is enabled.

See Also:
captureStandardOutput(org.gradle.api.logging.LogLevel)

captureStandardOutput

@Deprecated
void captureStandardOutput(LogLevel level)
Deprecated. Use the LoggingManager returned by getLogging() instead

Starts redirection of standard output during to the logging system during project evaluation. By default redirection is enabled and the output is redirected to the QUIET level. System.err is always redirected to the ERROR level. Redirection of output at execution time can be configured via the tasks.

In a multi-project this is a per-project setting.

Parameters:
level - The level standard out should be logged to.
See Also:
disableStandardOutputCapture(), Task.captureStandardOutput(org.gradle.api.logging.LogLevel), Task.disableStandardOutputCapture()

configure

Object configure(Object object,
                 Closure configureClosure)

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() }
 

Parameters:
object - The object to configure
configureClosure - The closure with configure statements
Returns:
The configured object

configure

Iterable<?> configure(Iterable<?> objects,
                      Closure configureClosure)
Configures a collection of objects via a closure. This is equivalent to calling configure(Object, groovy.lang.Closure) for each of the given objects.

Parameters:
objects - The objects to configure
configureClosure - The closure with configure statements
Returns:
The configured objects.

configure

<T> Iterable<T> configure(Iterable<T> objects,
                          Action<? super T> configureAction)
Configures a collection of objects via an action.

Parameters:
objects - The objects to configure
configureAction - The action to apply to each object
Returns:
The configured objects.

getRepositories

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

Returns:
the repository handler. Never returns null.

repositories

void repositories(Closure configureClosure)
Configures the repositories for this project. Executes the given closure against the RepositoryHandler for this project. The RepositoryHandler is passed to the closure as the closure's delegate.

Parameters:
configureClosure - the closure to use to configure the repositories.

createRepositoryHandler

RepositoryHandler createRepositoryHandler()
Creates a new repository handler.

Each repository handler is a factory and container for repositories. For example each instance of an upload task has its own repository handler.

Returns:
a new repository handler

getDependencies

DependencyHandler getDependencies()
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.

Returns:
the dependency handler. Never returns null.
See Also:
getConfigurations()

dependencies

void dependencies(Closure configureClosure)
Configures the dependencies for this project. Executes the given closure against the DependencyHandler for this project. The DependencyHandler is passed to the closure as the closure's delegate.

Parameters:
configureClosure - the closure to use to configure the dependencies.

getPlugins

PluginContainer getPlugins()
Returns the plugins container for this project. The returned container can be used to manage the plugins which are used by this project.

Returns:
the plugin container. Never returns null.

getBuildscript

ScriptHandler getBuildscript()
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.

Returns:
the classpath handler. Never returns null.

buildscript

void buildscript(Closure configureClosure)
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.

Parameters:
configureClosure - the closure to use to configure the build script classpath.

copy

WorkResult copy(Closure closure)
Copy 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'
    }
 }
 

Parameters:
closure - Closure to configure the CopySpec
Returns:
WorkResult that can be used to check if the copy did any work.

copySpec

CopySpec copySpec(Closure closure)
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.

Parameters:
closure - Closure to configure the CopySpec
Returns:
The CopySpec

apply

void apply(Closure closure)

Configures this project using plugins or scripts. The given closure is used to configure an ObjectConfigurationAction which is then used to configure this project.

Parameters:
closure - The closure to configure the ObjectConfigurationAction.

apply

void apply(Map<String,?> options)

Configures this project using plugins or scripts. The following options are available:

For more detail, see ObjectConfigurationAction.

Parameters:
options - The options to use to configure the ObjectConfigurationAction.

getState

ProjectState getState()
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.

Returns:
the project state. Never returns null.