Groovy Documentation

org.gradle.api
[Java] Interface Project


public interface Project
extends java.lang.Comparable

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

Lifecycle

There is a one-to-one relationship between a Project and a {

value:
#DEFAULT_BUILD_FILE} file. During build initialisation, Gradle assembles a Project object for each project which is to participate in the build, as follows:

Tasks

A project is essentially a collection of Task objects. Each task performs some basic piece of work, such as compiling classes, or running unit tests, or zipping up a WAR file. You add tasks to a project using one of the add() methods on TaskContainer, such as TaskContainer#add(String)#add(String). You can locate existing tasks using one of the lookup methods on TaskContainer, such as TaskContainer#getByName(String)#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:

Authors:
Hans Dockter


Field Summary
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 DEFAULT_STATUS

static java.lang.String DEFAULT_VERSION

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
 
Methods inherited from interface java.lang.Comparable
java.lang.Comparable#compareTo(java.lang.Object)
 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

DEFAULT_BUILD_DIR_NAME

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


DEFAULT_BUILD_FILE

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


DEFAULT_STATUS

public static final java.lang.String DEFAULT_STATUS


DEFAULT_VERSION

public static final java.lang.String DEFAULT_VERSION


GRADLE_PROPERTIES

public static final java.lang.String GRADLE_PROPERTIES


PATH_SEPARATOR

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


SYSTEM_PROP_PREFIX

public static final java.lang.String SYSTEM_PROP_PREFIX


TMP_DIR_NAME

public static final java.lang.String TMP_DIR_NAME


 

Groovy Documentation