|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface 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.
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:
Settings
instance for the build."settings.gradle"
script, if
present, against the Settings
object to configure it.Settings
object to create the hierarchy of
Project
instances.Project
by executing its "build.gradle"
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.
A project is essentially a collection of Task
objects. Each task performs some basic piece of work, such
as compiling classes, or running unit tests, or zipping up a WAR file. You add tasks to a project using one of the
add()
methods on TaskContainer
, such as TaskContainer.add(String)
. You can locate existing
tasks using one of the lookup methods on TaskContainer
, such as TaskCollection.getByName(String)
.
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 ConfigurationHandler
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.
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.
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.
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:
Project
object itself. This scope includes any property getters and setters declared by the
Project
implementation class. For example, getRootProject()
is accessable as the
rootProject
property. The properties of this scope are readable or writable depending on the presence
of the corresponding getter or setter method.Plugin
applied to the project. A Plugin
can add properties and methods to a project through the project's Convention
object. The properties
of this scope may be readable or writable, depending on the convention objects.compile
is accessable as the compile
property.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.
A project has 5 method 'scopes', which it searches for methods:
Project
object itself.Plugin
applied to the project. A Plugin
can add properties and method to a project through the project's Convention
object.Task.configure(groovy.lang.Closure)
method for the
associated task with the provided closure. For example, if the project has a task called compile
, then a
method is added with the following signature: void compile(Closure configureClosure)
.
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_GROUP
|
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 | |
---|---|
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<? super Project> action)
Adds an action to execute immediately after this project is evaluated. |
void |
afterEvaluate(groovy.lang.Closure closure)
Adds a closure to be called immediately after this project has been evaluated. |
void |
allprojects(Action<? super Project> action)
Executes the given Action against this project and its subprojects. |
void |
allprojects(groovy.lang.Closure configureClosure)
Executes the given closure against this project and its sub-projects. |
AntBuilder |
ant(groovy.lang.Closure configureClosure)
Executes the given closure against the AntBuilder for this project. |
void |
applyActions(java.util.Set<Project> projects,
Action<? super Project> action)
|
void |
artifacts(groovy.lang.Closure configureClosure)
Configures the published artifacts for this project. |
void |
beforeEvaluate(Action<? super Project> action)
Adds an action to execute immediately before this project is evaluated. |
void |
beforeEvaluate(groovy.lang.Closure closure)
Adds a closure to be called immediately before this project is evaluated. |
void |
buildscript(groovy.lang.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(groovy.lang.Closure configureClosure)
Configures the dependency configurations for this project. |
java.lang.Iterable<?> |
configure(java.lang.Iterable<?> objects,
groovy.lang.Closure configureClosure)
Configures a collection of objects via a closure. |
java.lang.Object |
configure(java.lang.Object object,
groovy.lang.Closure configureClosure)
Configures an object via a closure, with the closure's delegate set to the supplied object. |
WorkResult |
copy(groovy.lang.Closure closure)
Copy the specified files. |
AntBuilder |
createAntBuilder()
Creates an additional AntBuilder for this project. |
RepositoryHandler |
createRepositoryHandler()
Creates a new repository handler. |
Task |
createTask(java.util.Map<java.lang.String,?> args,
java.lang.String name)
Deprecated. |
Task |
createTask(java.util.Map<java.lang.String,?> args,
java.lang.String name,
groovy.lang.Closure action)
Deprecated. |
Task |
createTask(java.util.Map<java.lang.String,?> args,
java.lang.String name,
TaskAction action)
Deprecated. |
Task |
createTask(java.lang.String name)
Deprecated. |
Task |
createTask(java.lang.String name,
groovy.lang.Closure action)
Deprecated. |
Task |
createTask(java.lang.String name,
TaskAction action)
Deprecated. |
void |
defaultTasks(java.lang.String... defaultTasks)
Sets the names of the default tasks of this project. |
void |
dependencies(groovy.lang.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. |
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. |
ConfigurableFileCollection |
files(java.lang.Object... paths)
Returns a ConfigurableFileCollection containing the given files. |
ConfigurableFileCollection |
files(java.lang.Object paths,
groovy.lang.Closure configureClosure)
Creates a new ConfigurableFileCollection using the given paths. |
ConfigurableFileTree |
fileTree(groovy.lang.Closure closure)
Creates a new ConfigurableFileTree using the provided closure. |
ConfigurableFileTree |
fileTree(java.util.Map<java.lang.String,?> args)
Creates a new ConfigurableFileTree using the provided map of arguments. |
ConfigurableFileTree |
fileTree(java.lang.Object baseDir)
Creates a new ConfigurableFileTree using the given base directory. |
Project |
findProject(java.lang.String path)
Locates a project by path. |
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. |
AntBuilder |
getAnt()
Returns the AntBuilder for this project. |
ArtifactHandler |
getArtifacts()
Returns a handler for assigning artifacts produced by the project to configurations. |
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.io.File |
getBuildFile()
Returns the build file Gradle will evaulate against this project object. |
ScriptHandler |
getBuildscript()
Returns the build script handler for this project. |
java.util.Map<java.lang.String,Project> |
getChildProjects()
Returns the direct children of this project. |
ConfigurationHandler |
getConfigurations()
Returns the configurations 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. |
DependencyHandler |
getDependencies()
Returns the dependencies of 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. |
Gradle |
getGradle()
Returns the Gradle which this project belongs to. |
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. |
java.io.File |
getProjectDir()
The directory containing the project build file. |
java.util.Map<java.lang.String,?> |
getProperties()
Returns the properties of this project. |
RepositoryHandler |
getRepositories()
Returns a handler to create repositories which are used for retrieving dependencies and uploading artifacts produced by the project. |
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.lang.Object |
getStatus()
Returns the status of this project. |
java.util.Set<Project> |
getSubprojects()
Returns the set containing the subprojects of this project. |
TaskContainer |
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. |
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,
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 |
repositories(groovy.lang.Closure configureClosure)
Configures the repositories for this project. |
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(Action<? super Project> action)
Executes the given Action against the subprojects of this project. |
void |
subprojects(groovy.lang.Closure configureClosure)
Executes the given closure against each of the sub-projects of this project. |
Task |
task(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 |
task(java.util.Map<java.lang.String,?> args,
java.lang.String name,
groovy.lang.Closure configureClosure)
Creates a Task with the given name and adds it to this project. |
Task |
task(java.lang.String name)
Creates a Task with the given name and adds it to this project. |
Task |
task(java.lang.String name,
groovy.lang.Closure configureClosure)
Creates a Task with the given name and adds it to this project. |
Project |
usePlugin(java.lang.Class<? extends Plugin> pluginClass)
Applies a Plugin to this project. |
Project |
usePlugin(java.lang.String pluginName)
Applies a Plugin to this project. |
Methods inherited from interface java.lang.Comparable |
---|
compareTo |
Field Detail |
---|
static final java.lang.String DEFAULT_BUILD_FILE
static final java.lang.String PATH_SEPARATOR
static final java.lang.String DEFAULT_BUILD_DIR_NAME
static final java.lang.String GRADLE_PROPERTIES
static final java.lang.String SYSTEM_PROP_PREFIX
static final java.lang.String TMP_DIR_NAME
static final java.lang.String DEFAULT_GROUP
static final java.lang.String DEFAULT_VERSION
static final java.lang.String DEFAULT_STATUS
Method Detail |
---|
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
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
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
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
void setBuildDirName(java.lang.String buildDirName)
Sets the build directory name of this project.
buildDirName
- The build dir name. Should not be null.java.io.File getBuildFile()
Returns the build file Gradle will evaulate against this project object. The default is "build.gradle"
. If an embedded script is provided the build file will be null.
You can access this property in your build file using buildFile
Project getParent()
Returns the parent project of this project, if any.
You can access this property in your build file using parent
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
java.lang.Object getGroup()
Returns the group of this project. Gradle always uses the toString() value of a group. The group defaults to "unspecified".
You can access this property in your build file using group
java.lang.Object getVersion()
Returns the version of this project. Gradle always uses the toString() value of a version. The version defaults to "unspecified".
You can access this property in your build file using version
java.lang.Object getStatus()
Returns the status of this project. Gradle always uses the toString() value of a version. The status defaults to "release".
You can access this property in your build file using status
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
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
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.
rootDir
project property.Convention
object. For example, the srcRootName
java plugin
property.If the property is not found in any of these locations, it is added to the project's additional properties.
name
- The name of the propertyvalue
- The value of the propertyProject 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
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
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
Project usePlugin(java.lang.String pluginName)
Applies a Plugin
to this project.
pluginName
- The name of the plugin.
Project usePlugin(java.lang.Class<? extends Plugin> pluginClass)
Applies a Plugin
to this project.
pluginClass
- The class of the plugin. This class must implement the Plugin
interface.
Task task(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 task(java.util.Map, String)
with an empty options map.
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project, an exception is thrown.
name
- The name of the task to be created
InvalidUserDataException
- If a task with the given name already exists in this project.Task task(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:
Option | Description | Default Value |
---|---|---|
"type" | The class of the task to create. | DefaultTask |
"overwrite" | Replace an existing task? | false |
"dependsOn" | A task name or set of task names which this task depends on | [] |
"action" | A closure or TaskAction to add to
the task. | null |
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project and the override
option is not set
to true, an exception is thrown.
args
- The task creation options.name
- The name of the task to be created
InvalidUserDataException
- If a task with the given name already exists in this project.Task task(java.util.Map<java.lang.String,?> args, java.lang.String name, groovy.lang.Closure configureClosure)
Creates a Task
with the given name and adds it to this project. Before the task is returned, the given
closure is executed to configure the task. A map of creation options can be passed to this method to control how
the task is created. See task(java.util.Map, String)
for the available options.
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project and the override
option is not set
to true, an exception is thrown.
args
- The task creation options.name
- The name of the task to be createdconfigureClosure
- The closure to use to configure the created task.
InvalidUserDataException
- If a task with the given name already exists in this project.Task task(java.lang.String name, groovy.lang.Closure configureClosure)
Creates a Task
with the given name and adds it to this project. Before the task is returned, the given
closure is executed to configure the task.
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
name
- The name of the task to be createdconfigureClosure
- The closure to use to configure the created task.
InvalidUserDataException
- If a task with the given name already exists in this project.@Deprecated 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.
name
- The name of the task to be created
InvalidUserDataException
- If a task with the given name already exists in this project.@Deprecated 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 is passed to the task's Task.doFirst(Action)
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.
name
- The name of the task to be createdaction
- The action to be passed to the Task.doFirst(Action)
method of the created task.
InvalidUserDataException
- If a task with the given name already exists in this project.@Deprecated 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:
Option | Description | Default Value |
---|---|---|
"type" | The class of the task to create. | DefaultTask |
"overwrite" | Replace an existing task? | false |
"dependsOn" | A task name or set of task names which this task depends on | [] |
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project and the override
option is not set
to true, an exception is thrown.
args
- The task creation options.name
- The name of the task to be created
InvalidUserDataException
- If a task with the given name already exists in this project.@Deprecated 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 is passed to the task's Task.doFirst(Action)
method. A map of creation options can be passed to
this method to control how the task is created. See createTask(java.util.Map, String)
for the available
options.
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project and the override
option is not set
to true, an exception is thrown.
args
- The task creation options.name
- The name of the task to be createdaction
- The action to be passed to the Task.doFirst(Action)
method of the created task.
InvalidUserDataException
- If a task with the given name already exists in this project.@Deprecated 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.
name
- The name of the task to be createdaction
- The closure to be passed to the Task.doFirst(Closure)
method of the created task.
InvalidUserDataException
- If a task with the given name already exists in this project.@Deprecated 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.
args
- The task creation options.name
- The name of the task to be createdaction
- The closure to be passed to the Task.doFirst(Closure)
method of the created task.
InvalidUserDataException
- If a task with the given name already exists in this project.java.lang.String getPath()
Returns the path of this project. The path is the fully qualified name of the project.
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.
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.
defaultTasks
- The default task names.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.
defaultTasks
- The default task names.void dependsOn(java.lang.String path) throws UnknownProjectException
Declares that this project has an execution dependency on the project with the given path.
path
- The path of the project which this project depends on.
UnknownProjectException
- If no project with the given path exists.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.
path
- The path of the project which this project depends on.evaluateDependsOnProject
- If true, adds an evaluation dependency.
UnknownProjectException
- If no project with the given path exists.Project evaluationDependsOn(java.lang.String path) throws UnknownProjectException
Declares that this project has an evaulation dependency on the project with the given path.
path
- The path of the project which this project depends on.
UnknownProjectException
- If no project with the given path exists.Project childrenDependOnMe()
Declares that all child projects of this project have an execution dependency on this project.
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.
evaluateDependsOnProject
- If true, adds an evaluation dependency.
Project findProject(java.lang.String path)
Locates a project by path. If the path is relative, it is interpreted relative to this project.
path
- The path.
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.
path
- The path.
UnknownProjectException
- If no project with the given path exists.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. The target project is passed to the closure as the closure's delegate.
path
- The path.configureClosure
- The closure to use to configure the project.
UnknownProjectException
- If no project with the given path exists.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.
recursive
- If true, returns the tasks of this project and its subprojects. If false, returns the tasks of
just this project.
java.util.Set<Task> getTasksByName(java.lang.String name, boolean recursive)
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.
java.io.File getProjectDir()
The directory containing the project build file.
You can access this property in your build file using projectDir
java.io.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.
path
- An object who's toString method value is interpreted as a path to a 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.
path
- An object which toString method value is interpreted as a relative path to the project directory.validation
- The validation to perform on the file.
InvalidUserDataException
- When the file does not meet the given validation constraint.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.
path
- An object which toString method value is interpreted as path.
ConfigurableFileCollection files(java.lang.Object... paths)
Returns a ConfigurableFileCollection
containing the given files. You can pass any of the following
types to this method:
String
. Interpreted relative to the project directory, as a call to file(Object)
.Collection
or an array. May contain any of the types listed here. The elements of the collection
are recursively converted to files.FileCollection
. The contents of the collection are included in the returned
collection.Callable
. The call()
method may return any of the types listed here.
The return value of the call()
method is recursively converted to files. A null
return value is
treated as an empty collection.null
return value is treated as an empty collection.toString()
value is treated the same way as a String, as per a call to file(Object)
.The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.
The returned file collection maintains the iteration order of the supplied paths.
paths
- The paths to the files. May be empty.
ConfigurableFileCollection files(java.lang.Object paths, groovy.lang.Closure configureClosure)
Creates a new ConfigurableFileCollection
using the given paths. The paths are evaluated as for files(Object...)
. The file collection is configured using the given closure. The file collection is passed to
the closure as its delegate. Example:
files "$buildDir/classes" { builtBy 'compile' }
The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.
paths
- The contents of the file collection. Evaluated as for files(Object...)
.configureClosure
- The closure to use to configure the file collection.
ConfigurableFileTree fileTree(java.lang.Object baseDir)
Creates a new ConfigurableFileTree
using the given base directory. The given baseDir path is evaluated
as for file(Object)
.
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
baseDir
- The base directory of the file tree. Evaluated as for file(Object)
.
ConfigurableFileTree fileTree(java.util.Map<java.lang.String,?> args)
Creates a new ConfigurableFileTree
using the provided map of arguments. The map will be applied as
properties on the new file tree. Example:
fileTree(dir:'src', excludes:['**/ignore/**','**/.svn/**'])
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
args
- map of property assignments to ConfigurableFileTree
object
ConfigurableFileTree fileTree(groovy.lang.Closure closure)
Creates a new ConfigurableFileTree
using the provided closure. The closure will be used to configure
the new file tree. The file tree is passed to the closure as its delegate. Example:
fileTree { from 'src' exclude '**/.svn/**' }.copy { into 'dest'}
The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
closure
- Closure to configure the ConfigurableFileTree
object
java.lang.String absolutePath(java.lang.String path)
Converts a name to an absolute project path, resolving names relative to this project.
path
- The path to convert.
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
AntBuilder
for this project. Never returns null.AntBuilder createAntBuilder()
Creates an additional AntBuilder
for this project. You can use this in your build file to execute
ant tasks.
AntBuilder
for this project. Never returns null.getAnt()
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. 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.
configureClosure
- The closure to execute against the AntBuilder
.
AntBuilder
. Never returns null.ConfigurationHandler getConfigurations()
void configurations(groovy.lang.Closure configureClosure)
ConfigurationHandler
for this project. The ConfigurationHandler
is passed to the closure as the
closure's delegate.
configureClosure
- the closure to use to configure the dependency configurations.ArtifactHandler getArtifacts()
void artifacts(groovy.lang.Closure configureClosure)
ArtifactHandler
for this project. The ArtifactHandler
is passed to the closure as the closure's
delegate.
configureClosure
- the closure to use to configure the published artifacts.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
Convention
. Never returns null.int depthCompare(Project otherProject)
Compares the nesting level of this project with another project of the multi-project hierarchy.
otherProject
- The project to compare the nesting level with.
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.
TaskContainer getTasks()
Returns the tasks of this project.
void subprojects(Action<? super Project> action)
Executes the given Action
against the subprojects of this project.
action
- The action to execute.void subprojects(groovy.lang.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.
configureClosure
- The closure to execute. The closure receives no parameters.void allprojects(Action<? super Project> action)
Executes the given Action
against this project and its subprojects.
action
- The action to execute.void allprojects(groovy.lang.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.
configureClosure
- The closure to execute. The closure receives no parameters.void applyActions(java.util.Set<Project> projects, Action<? super Project> action)
projects
- action
- void beforeEvaluate(Action<? super Project> action)
action
- the action to execute.void afterEvaluate(Action<? super Project> action)
action
- the action to execute.void beforeEvaluate(groovy.lang.Closure closure)
Adds a closure to be called immediately before this project is evaluated. The project is passed to the closure as a parameter.
closure
- The closure to call.void afterEvaluate(groovy.lang.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.
closure
- The closure to call.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.
propertyName
- The name of the property to locate.
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.
java.lang.Object property(java.lang.String propertyName) throws groovy.lang.MissingPropertyException
MissingPropertyException
propertyName
- The name of the property.
groovy.lang.MissingPropertyException
- When the given property is unknown.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
.
Gradle getGradle()
Returns the Gradle
which this project belongs to.
You can use this property in your build file using gradle
.
void disableStandardOutputCapture()
captureStandardOutput(org.gradle.api.logging.LogLevel)
void captureStandardOutput(LogLevel level)
StandardOutputLogging
.
level
- The level standard out should be logged to.disableStandardOutputCapture()
,
Task.captureStandardOutput(org.gradle.api.logging.LogLevel)
,
Task.disableStandardOutputCapture()
java.lang.Object configure(java.lang.Object object, groovy.lang.Closure configureClosure)
MyType myType = new MyType() myType.doThis() myType.doThat()you can do:
MyType myType = configure(new MyType()) { doThis() doThat() }
object
- The object to configureconfigureClosure
- The closure with configure statements
java.lang.Iterable<?> configure(java.lang.Iterable<?> objects, groovy.lang.Closure configureClosure)
configure(Object,
groovy.lang.Closure)
for each of the given objects.
objects
- The objects to configureconfigureClosure
- The closure with configure statements
RepositoryHandler getRepositories()
void repositories(groovy.lang.Closure configureClosure)
RepositoryHandler
for this project. The RepositoryHandler
is passed to the closure as the closure's delegate.
configureClosure
- the closure to use to configure the repositories.RepositoryHandler createRepositoryHandler()
DependencyHandler getDependencies()
getConfigurations()
void dependencies(groovy.lang.Closure configureClosure)
DependencyHandler
for this project. The DependencyHandler
is passed to the closure as the closure's delegate.
configureClosure
- the closure to use to configure the dependencies.ProjectPluginsContainer getPlugins()
ScriptHandler getBuildscript()
void buildscript(groovy.lang.Closure configureClosure)
ScriptHandler
. The ScriptHandler
is passed to the closure as the closure's delegate.
configureClosure
- the closure to use to configure the build script classpath.WorkResult copy(groovy.lang.Closure closure)
CopySpec
. Note that the
sources used in the from()
method may be one or more: copy { from configurations.runtime into 'build/deploy/lib' }Note that CopySpecs can be nested:
copy { into('build/webroot') exclude('**/.svn/**') from('src/main/webapp') { include '**/*.jsp' filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1']) } from('src/main/js') { include '**/*.js' } }
closure
- Closure to configure the CopySpec
WorkResult
that can be used to check if the copy did any work.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |