Groovy Documentation

org.gradle.api
Interface Project


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 can programmatically access all 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:

value:
org.gradle.api.initialization.Settings#DEFAULT_SETTINGS_FILE} script, if present, against the Settings object to configure it.
  • Use the configured Settings object to create the hierarchy of Project instances.
  • Finally, evaluate each Project by executing its {
  • value:
    #DEFAULT_BUILD_FILE} file, if present, against the project. The project are evaulated in breadth-wise order, such that a project is evaulated before its child projects. This order can be overridden by adding an evaluation dependency.

    Tasks

    A project is essentially a collection of org.gradle.api.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 TaskContainer#getByName(String).

    Dependencies

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

     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_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_GROUP

    static java.lang.String DEFAULT_STATUS

    static java.lang.String DEFAULT_VERSION

    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.

    void afterEvaluate(Action 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 action)

    Executes the given {

    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 applyActions(Set projects, Action action)

    void artifacts(Closure configureClosure)

    Configures the published artifacts for this project.

    void beforeEvaluate(Action 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)

    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.

    void configurations(Closure configureClosure)

    Configures the dependency configurations for this project.

    java.lang.Object configure(java.lang.Object object, Closure configureClosure)

    Configures an object via a closure, with the closure's delegate set to the supplied object.

    java.lang.Iterable configure(java.lang.Iterable objects, Closure configureClosure)

    Configures a collection of objects via a closure.

    AntBuilder createAntBuilder()

    Creates an additional AntBuilder for this project.

    RepositoryHandler createRepositoryHandler()

    Creates a new repository handler.

    Task createTask(java.lang.String name)

    Creates a {

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

    Creates a {

    Task createTask(Map args, java.lang.String name)

    Creates a {

    Task createTask(Map args, java.lang.String name, TaskAction action)

    Creates a {

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

    Creates a {

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

    Creates a {

    void defaultTasks(java.lang.String defaultTasks)

    Sets the names of the default tasks of this project.

    void dependencies(Closure configureClosure)

    Configures the dependencies 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.

    File file(java.lang.Object path)

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

    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.

    FileCollection files(java.lang.Object paths)

    Returns a {

    Project findProject(java.lang.String path)

    Locates a project by path.

    Map getAllTasks(boolean recursive)

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

    Set getAllprojects()

    Returns the set containing this project and its subprojects.

    AntBuilder getAnt()

    Returns the AntBuilder for this project.

    ArtifactHandler getArtifacts()

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

    Build getBuild()

    Returns the {

    File getBuildDir()

    Returns the build directory of this project.

    java.lang.String getBuildDirName()

    Returns the name of the build directory of this project.

    File getBuildFile()

    Returns the build file Gradle will evaulate against this project object.

    ScriptHandler getBuildscript()

    Returns the build script handler for this project.

    Map getChildProjects()

    Returns the direct children of this project.

    ConfigurationHandler getConfigurations()

    Returns the configurations of this project.

    Convention getConvention()

    Return the {

    List getDefaultTasks()

    Returns the names of the default tasks of this project.

    DependencyHandler getDependencies()

    Returns the dependencies of this project.

    Set 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.Object getGroup()

    Returns the group of this project.

    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.

    ProjectPluginsContainer getPlugins()

    Returns the plugins container for this project.

    Project getProject()

    Returns this project.

    File getProjectDir()

    The directory containing the project build file.

    Map 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.

    java.lang.Object getStatus()

    Returns the status of this project.

    Set getSubprojects()

    Returns the set containing the subprojects of this project.

    TaskContainer getTasks()

    Returns the tasks of this project.

    Set getTasksByName(java.lang.String name, boolean recursive)

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

    java.lang.Object getVersion()

    Returns the version of this project.

    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, 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.

    File relativePath(java.lang.Object path)

    Returns a file object with a relative path to the project directory.

    void repositories(Closure configureClosure)

    Configures the repositories for this project.

    void setBuildDirName(java.lang.String buildDirName)

    Sets the build directory name of this project.

    void setDefaultTasks(List 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(Action action)

    Executes the given {

    void subprojects(Closure configureClosure)

    Executes the given closure against each of the sub-projects of this project.

    Project usePlugin(java.lang.String pluginName)

    Applies a {

    Project usePlugin(java.lang.Class pluginClass)

    Applies a {

     
    Methods inherited from interface java.lang.Comparable
    compareTo
     
    Methods inherited from class java.lang.Object
    hashCode, getClass, equals, toString, wait, wait, wait, notify, notifyAll
     

    Field Detail

    CACHE_DIR_NAME

    static final java.lang.String CACHE_DIR_NAME


    DEFAULT_BUILD_DIR_NAME

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


    DEFAULT_BUILD_FILE

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


    DEFAULT_GROUP

    static final java.lang.String DEFAULT_GROUP


    DEFAULT_STATUS

    static final java.lang.String DEFAULT_STATUS


    DEFAULT_VERSION

    static final java.lang.String DEFAULT_VERSION


    EMBEDDED_SCRIPT_ID

    static final java.lang.String EMBEDDED_SCRIPT_ID


    GRADLE_PROPERTIES

    static final java.lang.String GRADLE_PROPERTIES


    PATH_SEPARATOR

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


    SYSTEM_PROP_PREFIX

    static final java.lang.String SYSTEM_PROP_PREFIX


    TMP_DIR_NAME

    static final java.lang.String TMP_DIR_NAME


     
    Method Detail

    absolutePath

    public java.lang.String absolutePath(java.lang.String path)

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

    param:
    path The path to convert.
    return:
    The absolute path.


    afterEvaluate

    public void afterEvaluate(Action action)
    Adds an action to execute immediately after this project is evaluated.
    param:
    action the action to execute.


    afterEvaluate

    public 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.

    param:
    closure The closure to call.


    allprojects

    public void allprojects(Action action)

    Executes the given org.gradle.api.Action against this project and its subprojects.

    param:
    action The action to execute.


    allprojects

    public 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.

    param:
    configureClosure The closure to execute. The closure receives no parameters.


    ant

    public 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.

    param:
    configureClosure The closure to execute against the AntBuilder.
    return:
    The AntBuilder. Never returns null.


    applyActions

    public void applyActions(Set projects, Action action)
    param:
    projects
    param:
    action


    artifacts

    public void artifacts(Closure configureClosure)
    Configures the published artifacts for this project. Executes the given closure against the org.gradle.api.artifacts.dsl.ArtifactHandler for this project. The org.gradle.api.artifacts.dsl.ArtifactHandler is passed to the closure as the closure's delegate.
    param:
    configureClosure the closure to use to configure the published artifacts.


    beforeEvaluate

    public void beforeEvaluate(Action action)
    Adds an action to execute immediately before this project is evaluated.
    param:
    action the action to execute.


    beforeEvaluate

    public 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.

    param:
    closure The closure to call.


    buildscript

    public 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.
    param:
    configureClosure the closure to use to configure the build script classpath.


    captureStandardOutput

    public 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 org.gradle.api.logging.StandardOutputLogging.
    param:
    level The level standard out should be logged to.
    see:
    #disableStandardOutputCapture()
    see:
    Task#captureStandardOutput(org.gradle.api.logging.LogLevel)
    see:
    org.gradle.api.Task#disableStandardOutputCapture()


    childrenDependOnMe

    public Project childrenDependOnMe()

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

    return:
    this project.


    configurations

    public void configurations(Closure configureClosure)
    Configures the dependency configurations for this project. Executes the given closure against the org.gradle.api.artifacts.dsl.ConfigurationHandler for this project. The org.gradle.api.artifacts.dsl.ConfigurationHandler is passed to the closure as the closure's delegate.
    param:
    configureClosure the closure to use to configure the dependency configurations.


    configure

    public java.lang.Object configure(java.lang.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()
     }
     
    param:
    object The object to configure
    param:
    configureClosure The closure with configure statements
    return:
    The configured object


    configure

    public java.lang.Iterable configure(java.lang.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.
    param:
    objects The objects to configure
    param:
    configureClosure The closure with configure statements
    return:
    The configured objects.


    createAntBuilder

    public AntBuilder createAntBuilder()

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

    return:
    Creates an AntBuilder for this project. Never returns null.
    see:
    #getAnt()


    createRepositoryHandler

    public 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.
    return:
    a new repository handler


    createTask

    @Deprecated
    public Task createTask(java.lang.String name)

    Creates a org.gradle.api.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.

    param:
    name The name of the task to be created
    return:
    The newly created task object
    throws:
    InvalidUserDataException If a task with the given name already exists in this project.


    createTask

    @Deprecated
    public Task createTask(java.lang.String name, TaskAction action)

    Creates a org.gradle.api.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(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.

    param:
    name The name of the task to be created
    param:
    action The action to be passed to the Task#doFirst(TaskAction) method of the created task.
    return:
    The newly created task object
    throws:
    InvalidUserDataException If a task with the given name already exsists in this project.


    createTask

    @Deprecated
    public Task createTask(Map args, java.lang.String name)

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

    OptionDescriptionDefault Value
    {
    value:
    org.gradle.api.Task#TASK_TYPE}
    The class of the task to create.org.gradle.api.DefaultTask
    {
    value:
    org.gradle.api.Task#TASK_OVERWRITE}
    Replace an existing task?false
    {
    value:
    org.gradle.api.Task#TASK_DEPENDS_ON}
    A task name or set of task names which this task depends on[]

    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.

    param:
    args The task creation options.
    param:
    name The name of the task to be created
    return:
    The newly created task object
    throws:
    InvalidUserDataException If a task with the given name already exsists in this project.


    createTask

    @Deprecated
    public Task createTask(Map args, java.lang.String name, TaskAction action)

    Creates a org.gradle.api.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(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.

    param:
    args The task creation options.
    param:
    name The name of the task to be created
    param:
    action The action to be passed to the Task#doFirst(TaskAction) method of the created task.
    return:
    The newly created task object
    throws:
    InvalidUserDataException If a task with the given name already exsists in this project.


    createTask

    @Deprecated
    public Task createTask(java.lang.String name, Closure action)

    Creates a org.gradle.api.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.

    param:
    name The name of the task to be created
    param:
    action The closure to be passed to the Task#doFirst(Closure) method of the created task.
    return:
    The newly created task object
    throws:
    InvalidUserDataException If a task with the given name already exsists in this project.


    createTask

    @Deprecated
    public Task createTask(Map args, java.lang.String name, Closure action)

    Creates a org.gradle.api.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.

    param:
    args The task creation options.
    param:
    name The name of the task to be created
    param:
    action The closure to be passed to the Task#doFirst(Closure) method of the created task.
    return:
    The newly created task object
    throws:
    InvalidUserDataException If a task with the given name already exsists in this project.


    defaultTasks

    public 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.

    param:
    defaultTasks The default task names.


    dependencies

    public void dependencies(Closure configureClosure)
    Configures the dependencies for this project. Executes the given closure against the org.gradle.api.artifacts.dsl.DependencyHandler for this project. The org.gradle.api.artifacts.dsl.DependencyHandler is passed to the closure as the closure's delegate.
    param:
    configureClosure the closure to use to configure the dependencies.


    dependsOn

    public void dependsOn(java.lang.String path)

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

    param:
    path The path of the project which this project depends on.
    throws:
    UnknownProjectException If no project with the given path exists.


    dependsOn

    public void dependsOn(java.lang.String path, boolean evaluateDependsOnProject)

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

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


    dependsOnChildren

    public Project dependsOnChildren()

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

    return:
    this project.


    dependsOnChildren

    public Project dependsOnChildren(boolean evaluateDependsOnProject)

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

    param:
    evaluateDependsOnProject If true, adds an evaluation dependency.
    return:
    this project.


    depthCompare

    public int depthCompare(Project otherProject)

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

    param:
    otherProject The project to compare the nesting level with.
    return:
    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:
    #getDepth()


    disableStandardOutputCapture

    public void disableStandardOutputCapture()
    Disables redirection of standard output during project evaluation. By default redirection is enabled.
    see:
    #captureStandardOutput(org.gradle.api.logging.LogLevel)


    evaluationDependsOn

    public Project evaluationDependsOn(java.lang.String path)

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

    param:
    path The path of the project which this project depends on.
    return:
    The project which this project depends on.
    throws:
    UnknownProjectException If no project with the given path exists.


    file

    public File file(java.lang.Object path)

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

    path.toString will be used to get a string path. If this string can be interpreted as a relative path, the project directory will be used as a base directory.

    param:
    path An object who's toString method value is interpreted as a path to a file.
    return:
    The resolved file. Never returns null.


    file

    public 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. See org.gradle.api.PathValidation for the list of possible validations.

    param:
    path An object which toString method value is interpreted as a relative path to the project directory.
    return:
    The resolved file. Never returns null.
    throws:
    InvalidUserDataException When the file does not meet the given validation constraint.


    files

    public FileCollection files(java.lang.Object paths)

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

    The returned FileCollection is 'live', in that it evaluates the above each time the contents of the collection is queried.

    param:
    paths The paths to the files. May be empty.
    return:
    The file collection. Never returns null.


    findProject

    public Project findProject(java.lang.String path)

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

    param:
    path The path.
    return:
    The project with the given path. Returns null if no such project exists.


    getAllTasks

    public Map getAllTasks(boolean recursive)

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

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


    getAllprojects

    public Set getAllprojects()

    Returns the set containing this project and its subprojects.

    You can access this property in your build file using allprojects

    return:
    The set of projects.


    getAnt

    public 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

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


    getArtifacts

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


    getBuild

    public Build getBuild()

    Returns the Build which this project belongs to.

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

    return:
    The build. Never returns null.


    getBuildDir

    public 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

    return:
    The build directory. Never returns null.


    getBuildDirName

    public 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 {

    value:
    #DEFAULT_BUILD_DIR_NAME}.

    You can access this property in your build file using buildDirName

    return:
    The build dir name. Never returns null.


    getBuildFile

    public File getBuildFile()

    Returns the build file Gradle will evaulate against this project object. The default is {

    value:
    #DEFAULT_BUILD_FILE}. If an embedded script is provided the build file will be null.

    You can access this property in your build file using buildFile

    return:
    Current build file. May return null.


    getBuildscript

    public ScriptHandler getBuildscript()
    Returns the build script handler for this project. You can use this handler to manage the classpath used to compile and execute the project's build script.
    return:
    the classpath handler. Never returns null.


    getChildProjects

    public Map getChildProjects()

    Returns the direct children of this project.

    You can access this property in your build file using childProjects

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


    getConfigurations

    public ConfigurationHandler getConfigurations()
    Returns the configurations of this project.
    return:
    The configuration of this project.


    getConvention

    public 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

    return:
    The Convention. Never returns null.


    getDefaultTasks

    public List getDefaultTasks()

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

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


    getDependencies

    public DependencyHandler getDependencies()
    Returns the dependencies 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.
    return:
    the dependency handler. Never returns null.
    see:
    #getConfigurations()


    getDependsOnProjects

    public Set getDependsOnProjects()

    Returns the set of projects which this project depends on.

    You can access this property in your build file using dependsOnProjects

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


    getDepth

    public 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.


    getGroup

    public java.lang.Object getGroup()

    Returns the group of this project. Gradle always uses the toString() value of a group.

    You can access this property in your build file using group

    return:
    The group of this project. Defaults to #DEFAULT_GROUP


    getLogger

    public 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.

    return:
    The logger. Never returns null.


    getName

    public 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

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


    getParent

    public Project getParent()

    Returns the parent project of this project, if any.

    You can access this property in your build file using parent

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


    getPath

    public java.lang.String getPath()

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

    return:
    The path. Never returns null.


    getPlugins

    public ProjectPluginsContainer getPlugins()
    Returns the plugins container for this project. The returned container can be used to manage the plugins which are used by this project.
    return:
    the plugin container. Never returns null.


    getProject

    public 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

    return:
    This project. Never returns null.


    getProjectDir

    public File getProjectDir()

    The directory containing the project build file.

    You can access this property in your build file using projectDir

    return:
    The project directory. Never returns null.


    getProperties

    public Map getProperties()

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

    return:
    A map from property name to value.


    getRepositories

    public RepositoryHandler getRepositories()
    Returns a handler to create repositories which are used for retrieving dependencies and uploading artifacts produced by the project.
    return:
    the repository handler. Never returns null.


    getRootDir

    public 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

    return:
    The root directory. Never returns null.


    getRootProject

    public 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

    return:
    The root project. Never returns null.


    getStatus

    public java.lang.Object getStatus()

    Returns the status of this project. Gradle always uses the toString() value of a version.

    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.
    return:
    The status of this project. Defaults to #DEFAULT_STATUS


    getSubprojects

    public Set getSubprojects()

    Returns the set containing the subprojects of this project.

    You can access this property in your build file using subprojects

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


    getTasks

    public TaskContainer getTasks()

    Returns the tasks of this project.

    return:
    the tasks of this project.


    getTasksByName

    public Set getTasksByName(java.lang.String name, boolean recursive)
    Returns the set of tasks with the given name contained in this project, and optionally its subprojects.

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


    getVersion

    public java.lang.Object getVersion()

    Returns the version of this project. Gradle always uses the toString() value of a version.

    You can access this property in your build file using version

    return:
    The version of this project. Defaults to #DEFAULT_VERSION


    hasProperty

    public 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.

    param:
    propertyName The name of the property to locate.
    return:
    True if this project has the given property, false otherwise.


    project

    public Project project(java.lang.String path)

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

    param:
    path The path.
    return:
    The project with the given path. Never returns null.
    throws:
    UnknownProjectException If no project with the given path exists.


    project

    public Project project(java.lang.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.

    param:
    path The path.
    param:
    configureClosure The closure to use to configure the project.
    return:
    The project with the given path. Never returns null.
    throws:
    UnknownProjectException If no project with the given path exists.


    property

    public java.lang.Object property(java.lang.String propertyName)
    Returns the value of the given property. This method locates a property as follows:

    1. If this project object has a property with the given name, return the value of the property.
    2. If this project'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
    param:
    propertyName The name of the property.
    return:
    The value of the property, possibly null.
    throws:
    MissingPropertyException When the given property is unknown.


    relativePath

    public 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.

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


    repositories

    public void repositories(Closure configureClosure)
    Configures the repositories for this project. Executes the given closure against the org.gradle.api.artifacts.dsl.RepositoryHandler for this project. The org.gradle.api.artifacts.dsl.RepositoryHandler is passed to the closure as the closure's delegate.
    param:
    configureClosure the closure to use to configure the repositories.


    setBuildDirName

    public void setBuildDirName(java.lang.String buildDirName)

    Sets the build directory name of this project.

    param:
    buildDirName The build dir name. Should not be null.


    setDefaultTasks

    public void setDefaultTasks(List defaultTasks)

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

    param:
    defaultTasks The default task names.


    setProperty

    public 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.

    param:
    name The name of the property
    param:
    value The value of the property


    subprojects

    public void subprojects(Action action)

    Executes the given org.gradle.api.Action against the subprojects of this project.

    param:
    action The action to execute.


    subprojects

    public 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.

    param:
    configureClosure The closure to execute. The closure receives no parameters.


    usePlugin

    public Project usePlugin(java.lang.String pluginName)

    Applies a org.gradle.api.Plugin to this project.

    param:
    pluginName The name of the plugin.
    return:
    This project.


    usePlugin

    public Project usePlugin(java.lang.Class pluginClass)

    Applies a org.gradle.api.Plugin to this project.

    param:
    pluginClass The class of the plugin. This class must implement the org.gradle.api.Plugin interface.
    return:
    This project.


     

    Groovy Documentation