org.gradle.api
Interface Project

All Superinterfaces:
java.lang.Comparable<Project>

public interface Project
extends java.lang.Comparable<Project>

This interface is the main API you use to interact with Gradle from your build file. From a Project, you can programmatically access all 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 createTask(String) methods. You can locate existing tasks using one of the task(String) methods.

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. You use the DependencyManager returned by getDependencies() method to manage the dependencies and artifacts of the project.

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:

 createTask('some-task')  // Delegates to Project.createTask()
 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:

Author:
Hans Dockter

Field Summary
static java.lang.String CACHE_DIR_NAME
           
static java.lang.String DEFAULT_ARCHIVES_TASK_BASE_NAME
           
static java.lang.String DEFAULT_BUILD_DIR_NAME
          The default build directory name.
static java.lang.String DEFAULT_BUILD_FILE
          The default project build file name.
static java.lang.String EMBEDDED_SCRIPT_ID
           
static java.lang.String GRADLE_PROPERTIES
           
static java.lang.String PATH_SEPARATOR
          The hierarchy separator for project and task path names
static java.lang.String SYSTEM_PROP_PREFIX
           
static java.lang.String TMP_DIR_NAME
           
 
Method Summary
 java.lang.String absolutePath(java.lang.String path)
          Converts a name to an absolute project path, resolving names relative to this project.
 AfterEvaluateListener addAfterEvaluateListener(AfterEvaluateListener afterEvaluateListener)
          Adds an AfterEvaluateListener to this project.
 void addAfterEvaluateListener(groovy.lang.Closure afterEvaluateListener)
          Adds the given closure as an AfterEvaluateListener.
 void allprojects(groovy.lang.Closure configureClosure)
          Executes the given closure against this project and its subprojects.
 void allprojects(ProjectAction action)
          Executes the given ProjectAction against this project and its subprojects.
 groovy.util.AntBuilder ant(groovy.lang.Closure configureClosure)
          Executes the given closure against the AntBuilder for this project.
 void applyActions(java.util.Set<Project> projects, ProjectAction action)
           
 void captureStandardOutput(LogLevel level)
          Starts redirection of standard output during to the logging system during project evaluation.
 Project childrenDependOnMe()
          Declares that all child projects of this project have an execution dependency on this project.
 java.lang.Object configure(java.lang.Object object, groovy.lang.Closure configureClosure)
          Allows to configure an object via an closure.
 groovy.util.AntBuilder createAntBuilder()
          Creates and additional AntBuilder for this project.
 Task createTask(java.util.Map<java.lang.String,?> args, java.lang.String name)
          Creates a Task with the given name and adds it to this project.
 Task createTask(java.util.Map<java.lang.String,?> args, java.lang.String name, groovy.lang.Closure action)
          Creates a Task with the given name and adds it to this project.
 Task createTask(java.util.Map<java.lang.String,?> args, java.lang.String name, TaskAction action)
          Creates a Task with the given name and adds it to this project.
 Task createTask(java.lang.String name)
          Creates a Task with the given name and adds it to this project.
 Task createTask(java.lang.String name, groovy.lang.Closure action)
          Creates a Task with the given name and adds it to this project.
 Task createTask(java.lang.String name, TaskAction action)
          Creates a Task with the given name and adds it to this project.
 void defaultTasks(java.lang.String... defaultTasks)
          Sets the names of the default tasks of this project.
 DependencyManager dependencies(groovy.lang.Closure configureClosure)
          Executes the given closure against the DependencyManager for this project.
 void dependsOn(java.lang.String path)
          Declares that this project has an execution dependency on the project with the given path.
 void dependsOn(java.lang.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()
          Disables redirection of standard output during project evaluation.
 Project evaluationDependsOn(java.lang.String path)
          Declares that this project has an evaulation dependency on the project with the given path.
 java.io.File file(java.lang.Object path)
          Resolves a file path relative to the project directory of this project.
 java.io.File file(java.lang.Object path, PathValidation validation)
          Resolves a file path relative to the project directory of this project and validates it using the given scheme.
 Project findProject(java.lang.String path)
          Locates a project by path.
 Task findTask(java.lang.String path)
          Locates a Task by path.
 java.util.List<AfterEvaluateListener> getAfterEvaluateListeners()
          Returns all AfterEvaluateListeners of this project.
 java.util.Set<Project> getAllprojects()
          Returns the set containing this project and its subprojects.
 java.util.Map<Project,java.util.Set<Task>> getAllTasks(boolean recursive)
          Returns a map of the tasks contained in this project, and optionally its subprojects.
 groovy.util.AntBuilder getAnt()
          Returns the AntBuilder for this project.
 java.util.Set<java.lang.Class<? extends Plugin>> getAppliedPlugins()
          Returns the set of plugin types which have been applied to this project.
 java.lang.String getArchivesBaseName()
          Returns the default prefix for naming archives generated by bundle archive tasks.
 java.lang.String getArchivesTaskBaseName()
          Returns the default prefix for naming archive tasks created via Bundle tasks.
 Build getBuild()
          Returns the Build which this project belongs to.
 java.io.File getBuildDir()
          Returns the build directory of this project.
 java.lang.String getBuildDirName()
          Returns the name of the build directory of this project.
 java.lang.String getBuildFileClassName()
          Returns the name of the classname the build file compiles to.
 java.lang.String getBuildFileName()
          Returns the name of the build file Gradle tries to apply against this project object.
 java.util.Map<java.lang.String,Project> getChildProjects()
          Returns the direct children of this project.
 Convention getConvention()
          Return the Convention for this project.
 java.util.List<java.lang.String> getDefaultTasks()
          Returns the names of the default tasks of this project.
 DependencyManager getDependencies()
          Return the DependencyManager for this project.
 java.util.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.
 java.lang.String getGradleUserHome()
          Returns the home directory for a Gradle user.
 org.slf4j.Logger getLogger()
          Returns the logger for this project.
 java.lang.String getName()
          Returns the name of this project.
 Project getParent()
          Returns the parent project of this project, if any.
 java.lang.String getPath()
          Returns the path of this project.
 Project getProject()
          Returns this project.
 java.io.File getProjectDir()
          The directory containing the project build file.
 java.util.Map<java.lang.String,?> getProperties()
          Returns the properties of this project.
 java.io.File getRootDir()
          Returns the root directory of this project.
 Project getRootProject()
          Returns the root project for the hierarchy that this project belongs to.
 java.util.Set<Project> getSubprojects()
          Returns the set containing the subprojects of this project.
 java.util.Map<java.lang.String,Task> getTasks()
          Returns the tasks of this project.
 java.util.Set<Task> getTasksByName(java.lang.String name, boolean recursive)
          Returns the set of tasks with the given name contained in this project, and optionally its subprojects.
 boolean hasProperty(java.lang.String propertyName)
          Determines if this project has the given property.
 Project project(java.lang.String path)
          Locates a project by path.
 Project project(java.lang.String path, groovy.lang.Closure configureClosure)
          Locates a project by path and configures it using the given closure.
 java.lang.Object property(java.lang.String propertyName)
          Returns the value of the given property.
 java.io.File relativePath(java.lang.Object path)
          Returns a file object with a relative path to the project directory.
 void setArchivesBaseName(java.lang.String archivesBaseName)
          The default prefix for naming the archives generated by archive task.
 void setArchivesTaskBaseName(java.lang.String archivesTaskBaseName)
          Sets the default prefix used for naming archive tasks.
 void setBuildDirName(java.lang.String buildDirName)
          Sets the build directory name of this project.
 void setDefaultTasks(java.util.List<java.lang.String> defaultTasks)
          Sets the names of the default tasks of this project.
 void setProperty(java.lang.String name, java.lang.Object value)
          Sets a property of this project.
 void subprojects(groovy.lang.Closure configureClosure)
          Executes the given closure against each of the subprojects of this project.
 void subprojects(ProjectAction action)
          Executes the given ProjectAction against the subprojects of this project.
 Task task(java.lang.String path)
          Returns the Task from the project which has the given path.
 Task task(java.lang.String path, groovy.lang.Closure configurationClosure)
          Returns the Task from this project which has the given path.
 Project usePlugin(java.lang.Class<? extends Plugin> pluginClass)
          Applies a Plugin to this project.
 Project usePlugin(java.lang.Class<? extends Plugin> pluginClass, java.util.Map<java.lang.String,?> customValues)
          Applies a Plugin to this project.
 Project usePlugin(java.lang.String pluginName)
          Applies a Plugin to this project.
 Project usePlugin(java.lang.String pluginName, java.util.Map<java.lang.String,?> customValues)
          Applies a Plugin to this project.
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

DEFAULT_BUILD_FILE

static final java.lang.String DEFAULT_BUILD_FILE
The default project build file name.

See Also:
Constant Field Values

EMBEDDED_SCRIPT_ID

static final java.lang.String EMBEDDED_SCRIPT_ID
See Also:
Constant Field Values

DEFAULT_ARCHIVES_TASK_BASE_NAME

static final java.lang.String DEFAULT_ARCHIVES_TASK_BASE_NAME
See Also:
Constant Field Values

PATH_SEPARATOR

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

See Also:
Constant Field Values

DEFAULT_BUILD_DIR_NAME

static final java.lang.String DEFAULT_BUILD_DIR_NAME
The default build directory name.

See Also:
Constant Field Values

GRADLE_PROPERTIES

static final java.lang.String GRADLE_PROPERTIES
See Also:
Constant Field Values

SYSTEM_PROP_PREFIX

static final java.lang.String SYSTEM_PROP_PREFIX
See Also:
Constant Field Values

TMP_DIR_NAME

static final java.lang.String TMP_DIR_NAME
See Also:
Constant Field Values

CACHE_DIR_NAME

static final java.lang.String CACHE_DIR_NAME
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

java.io.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

java.io.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.

getBuildDirName

java.lang.String getBuildDirName()

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

void setBuildDirName(java.lang.String buildDirName)

Sets the build directory name of this project.

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

getGradleUserHome

java.lang.String getGradleUserHome()

Returns the home directory for a Gradle user. Default's to USER_HOME/.gradle

You can access this property in your build file using gradleUserHome

Returns:
The Gradle user directory. Never returns null.

getBuildFileName

java.lang.String getBuildFileName()

Returns the name of the build file Gradle tries to apply against this project object. The default is "build.gradle". If an embedded script is provided the build file name is "embedded_script".

You can access this property in your build file using buildFileName

Returns:
Current build file name. Never returns null.
See Also:
getBuildFileClassName()

getBuildFileClassName

java.lang.String getBuildFileClassName()

Returns the name of the classname the build file compiles to. They might be the same but not necessarily. If the build file name contains characters which are illegal for a class name, they are replaced in the build file name with underscores. In case of an embedded build script, the build file name and the build file class name are equal to "embedded_script". In case there is no build file provided for a project, Gradle injects an empty embedded script which obeys to the same naming convention as described above.

Returns:
Current build file class name. Never returns null.
See Also:
getBuildFileName()

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

java.lang.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.

getChildProjects

java.util.Map<java.lang.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

java.util.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(java.lang.String name,
                 java.lang.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 intent better than using name

You can access this property in your build file using project

Returns:
This project. Never returns null.

getAllprojects

java.util.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

java.util.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

Project usePlugin(java.lang.String pluginName)

Applies a Plugin to this project.

Parameters:
pluginName - The name of the plugin.
Returns:
This project.

usePlugin

Project usePlugin(java.lang.String pluginName,
                  java.util.Map<java.lang.String,?> customValues)

Applies a Plugin to this project.

Parameters:
pluginName - The name of the plugin.
customValues - Configuration parameters to use to apply the plugin to this project.
Returns:
This project.

usePlugin

Project usePlugin(java.lang.Class<? extends Plugin> pluginClass,
                  java.util.Map<java.lang.String,?> customValues)

Applies a Plugin to this project.

Parameters:
pluginClass - The class of the plugin. This class must implement the Plugin interface.
customValues - Configuration parameters to use to apply the plugin to this project.
Returns:
This project.

usePlugin

Project usePlugin(java.lang.Class<? extends Plugin> pluginClass)

Applies a Plugin to this project.

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

findTask

Task findTask(java.lang.String path)

Locates a Task by path. Relative paths are interpreted relative to this project. Returns null if no such task exists.

Parameters:
path - the path of the task to be returned
Returns:
The task. Returns null if so such task exists.

task

Task task(java.lang.String path)
          throws UnknownTaskException

Returns the Task from the project which has the given path. Relative paths are interpreted relative to this project. If no such task exists, an exception is thrown.

You can also call this method in your build file using the task name. See here for more details.

Parameters:
path - the path of the task to be returned
Returns:
The task. Never returns null.
Throws:
UnknownTaskException - If no task with the given path exists.

task

Task task(java.lang.String path,
          groovy.lang.Closure configurationClosure)
          throws UnknownTaskException

Returns the Task from this project which has the given path. Relative paths are interpreted relative to this project. Before the task is returned, the given closure is passed to the task's Task.configure(groovy.lang.Closure) method. If no such task exists, an exception is thrown.

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

Parameters:
path - the path of the task to be returned
configurationClosure - the closure to use to configure the task.
Returns:
The task. Never returns null.
Throws:
UnknownTaskException - If no task with the given path exists.

createTask

Task createTask(java.lang.String name)
                throws InvalidUserDataException

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

Task createTask(java.lang.String name,
                TaskAction action)
                throws InvalidUserDataException

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(TaskAction) method. Calling this method is equivalent to calling createTask(java.util.Map, String, TaskAction) 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(TaskAction) method of the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exsists in this project.

createTask

Task createTask(java.util.Map<java.lang.String,?> args,
                java.lang.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.org.gradle.api.internal.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 exsists in this project.

createTask

Task createTask(java.util.Map<java.lang.String,?> args,
                java.lang.String name,
                TaskAction action)
                throws InvalidUserDataException

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(TaskAction) 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(TaskAction) method of the created task.
Returns:
The newly created task object
Throws:
InvalidUserDataException - If a task with the given name already exsists in this project.

createTask

Task createTask(java.lang.String name,
                groovy.lang.Closure action)

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 exsists in this project.

createTask

Task createTask(java.util.Map<java.lang.String,?> args,
                java.lang.String name,
                groovy.lang.Closure action)

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 exsists in this project.

getArchivesTaskBaseName

java.lang.String getArchivesTaskBaseName()

Returns the default prefix for naming archive tasks created via Bundle tasks.

Returns:
The archivesTaskBaseName (never null)
See Also:
setArchivesBaseName(String)

setArchivesTaskBaseName

void setArchivesTaskBaseName(java.lang.String archivesTaskBaseName)

Sets the default prefix used for naming archive tasks. This is used if you create archive task via Bundle tasks. For example libs.jar() creates an archive task with the name of the default prefix plus "_jar". The default for the default prefix is archive.

Parameters:
archivesTaskBaseName - The value (never null) for the archivesTaskBaseName

getArchivesBaseName

java.lang.String getArchivesBaseName()

Returns the default prefix for naming archives generated by bundle archive tasks.

Returns:
The archivesBaseName (never null)
See Also:
setArchivesBaseName(String)

setArchivesBaseName

void setArchivesBaseName(java.lang.String archivesBaseName)

The default prefix for naming the archives generated by archive task. This is used if you create archive task via bundles. For example libs.jar() generates an archive with the name of the default prefix plus ".jar". The default for the default prefix is the name of the project.

Parameters:
archivesBaseName - The value (never null) for the archivesBaseName

getPath

java.lang.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

java.util.List<java.lang.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(java.util.List<java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String path,
                groovy.lang.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.

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

java.util.Map<Project,java.util.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

java.util.Set<Task> getTasksByName(java.lang.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

java.io.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

java.io.File file(java.lang.Object path)

Resolves a file path relative to the project directory of this project.

Parameters:
path - An object which toString method value is interpreted as a relative path to the project directory.
Returns:
The resolved file. Never returns null.

file

java.io.File file(java.lang.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.
Returns:
The resolved file. Never returns null.
Throws:
InvalidUserDataException - When the file does not meet the given validation constraint.

relativePath

java.io.File relativePath(java.lang.Object path)

Returns a file object with a relative path to the project directory. If the passed path is already a relative path, a file object with the same path is returned. If the passed path is an absolute path, a file object either the relative path to the project dir is returned, or null, if the absolute path has not the project dir as one of its parent dirs.

Parameters:
path - An object which toString method value is interpreted as path.
Returns:
A file with a relative path to the project dir, or null if the given path is outside the project dir.

absolutePath

java.lang.String absolutePath(java.lang.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.

getAnt

groovy.util.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

groovy.util.AntBuilder createAntBuilder()

Creates and 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

groovy.util.AntBuilder ant(groovy.lang.Closure configureClosure)

Executes the given closure against the AntBuilder for this project. You can use this in your build file to execute ant tasks.

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. The closure receives no paramters.
Returns:
The AntBuilder. Never returns null.

getDependencies

DependencyManager getDependencies()

Return the DependencyManager for this project.

You can access this property in your build file using dependencies

Returns:
The DependencyManager. Never returns null.

dependencies

DependencyManager dependencies(groovy.lang.Closure configureClosure)

Executes the given closure against the DependencyManager for this project.

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

Parameters:
configureClosure - The closure to execute against the DependencyManager. The closure receives no parameters.
Returns:
The DependencyManager. Never returns null.

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

java.util.Map<java.lang.String,Task> getTasks()

Returns the tasks of this project.

Returns:
A map from task name to Task object. Returns an empty map when this project has no tasks.

getAppliedPlugins

java.util.Set<java.lang.Class<? extends Plugin>> getAppliedPlugins()

Returns the set of plugin types which have been applied to this project.

Returns:
A set with class objects of plugins applied against this project. Returns an empty set if no plugins have been applied.

subprojects

void subprojects(ProjectAction action)

Executes the given ProjectAction against the subprojects of this project.

Parameters:
action - The action to execute.

subprojects

void subprojects(groovy.lang.Closure configureClosure)

Executes the given closure against each of the subprojects of this project.

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(ProjectAction action)

Executes the given ProjectAction against this project and its subprojects.

Parameters:
action - The action to execute.

allprojects

void allprojects(groovy.lang.Closure configureClosure)

Executes the given closure against this project and its subprojects.

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.

applyActions

void applyActions(java.util.Set<Project> projects,
                  ProjectAction action)
Parameters:
projects -
action -

addAfterEvaluateListener

AfterEvaluateListener addAfterEvaluateListener(AfterEvaluateListener afterEvaluateListener)

Adds an AfterEvaluateListener to this project. 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 there build files have been run.

Parameters:
afterEvaluateListener - The listener (never null) to be added.
Returns:
The added afterEvaluateListener
See Also:
AfterEvaluateListener

addAfterEvaluateListener

void addAfterEvaluateListener(groovy.lang.Closure afterEvaluateListener)

Adds the given closure as an AfterEvaluateListener. See addAfterEvaluateListener(AfterEvaluateListener) for more details.

Parameters:
afterEvaluateListener - The listener to be added.

getAfterEvaluateListeners

java.util.List<AfterEvaluateListener> getAfterEvaluateListeners()

Returns all AfterEvaluateListeners of this project.

See Also:
addAfterEvaluateListener(AfterEvaluateListener), AfterEvaluateListener

hasProperty

boolean hasProperty(java.lang.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

java.util.Map<java.lang.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

java.lang.Object property(java.lang.String propertyName)
                          throws groovy.lang.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:
groovy.lang.MissingPropertyException - When the given property is unknown.

getLogger

org.slf4j.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.

getBuild

Build getBuild()

Returns the Build which this project belongs to.

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

Returns:
The build. Never returns null.

disableStandardOutputCapture

void disableStandardOutputCapture()
Disables redirection of standard output during project evaluation. By default redirection is enabled.

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

captureStandardOutput

void captureStandardOutput(LogLevel level)
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. For more fine-grained control on redirecting standard output see StandardOutputLogging.

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

configure

java.lang.Object configure(java.lang.Object object,
                           groovy.lang.Closure configureClosure)
Allows to configure an object via an closure. That 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()
 }
 

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