Interface Project
-
- All Superinterfaces:
java.lang.Comparable<Project>
,ExtensionAware
,PluginAware
public interface Project extends java.lang.Comparable<Project>, ExtensionAware, PluginAware
This interface is the main API you use to interact with Gradle from your build file. From a
Project
, you have programmatic access to all of Gradle's features.Lifecycle
There is a one-to-one relationship between a
Project
and a"build.gradle"
file. During build initialisation, Gradle assembles aProject
object for each project which is to participate in the build, as follows:- Create a
Settings
instance for the build. - Evaluate the
"settings.gradle"
script, if present, against theSettings
object to configure it. - Use the configured
Settings
object to create the hierarchy ofProject
instances. - Finally, evaluate each
Project
by executing its"build.gradle"
file, if present, against the project. The projects are evaluated in breadth-wise order, such that a project is evaluated before its child projects. This order can be overridden by calling
or by adding an explicit evaluation dependency usingevaluationDependsOnChildren()
.evaluationDependsOn(String)
Tasks
A project is essentially a collection of
Task
objects. Each task performs some basic piece of work, such as compiling classes, or running unit tests, or zipping up a WAR file. You add tasks to a project using one of thecreate()
methods onTaskContainer
, such asTaskContainer.create(String)
. You can locate existing tasks using one of the lookup methods onTaskContainer
, such asTaskCollection.getByName(String)
.Dependencies
A project generally has a number of dependencies it needs in order to do its work. Also, a project generally produces a number of artifacts, which other projects can use. Those dependencies are grouped in configurations, and can be retrieved and uploaded from repositories. You use the
ConfigurationContainer
returned bygetConfigurations()
method to manage the configurations. TheDependencyHandler
returned bygetDependencies()
method to manage the dependencies. TheArtifactHandler
returned bygetArtifacts()
method to manage the artifacts. TheRepositoryHandler
returned bygetRepositories()
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.
Plugins
Plugins can be used to modularise and reuse project configuration. Plugins can be applied using the
PluginAware.apply(java.util.Map)
method, or by using thePluginDependenciesSpec
plugins script block.Dynamic Project Properties
Gradle executes the project's build file against the
Project
instance to configure the project. Any property or method which your script uses is delegated through to the associatedProject
object. This means, that you can use any of the methods and properties on theProject
interface directly in your script.For example:
defaultTasks('some-task') // Delegates to Project.defaultTasks() reportsDir = file('reports') // Delegates to Project.file() and the Java Plugin
You can also access the
Project
instance using theproject
property. This can make the script clearer in some cases. For example, you could useproject.name
rather thanname
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:- The
Project
object itself. This scope includes any property getters and setters declared by theProject
implementation class. For example,getRootProject()
is accessible as therootProject
property. The properties of this scope are readable or writable depending on the presence of the corresponding getter or setter method. - The extra properties of the project. Each project maintains a map of extra properties, which can contain any arbitrary name -> value pair. Once defined, the properties of this scope are readable and writable. See extra properties for more details.
- The extensions added to the project by the plugins. Each extension is available as a read-only property with the same name as the extension.
- The convention properties added to the project by the plugins. 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. - The tasks of the project. A task is accessible by using its name as a property name. The properties of this
scope are read-only. For example, a task called
compile
is accessible as thecompile
property. - The extra properties and convention properties are inherited from the project's parent, recursively up to the root project. The properties of this scope are read-only.
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. If not found, an exception is thrown. 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, an exception is thrown. See
setProperty(String, Object)
for more details.Extra Properties
All extra properties must be defined through the "ext" namespace. Once an extra property has been defined, it is available directly on the owning object (in the below case the Project, Task, and sub-projects respectively) and can be read and updated. Only the initial declaration that needs to be done via the namespace.
project.ext.prop1 = "foo" task doStuff { ext.prop2 = "bar" } subprojects { ext.${prop3} = false }
Reading extra properties is done through the "ext" or through the owning object.ext.isSnapshot = version.endsWith("-SNAPSHOT") if (isSnapshot) { // do snapshot stuff }
Dynamic Methods
A project has 5 method 'scopes', which it searches for methods:
- The
Project
object itself. - The build file. The project searches for a matching method declared in the build file.
- The extensions added to the project by the plugins. Each extension is available as a method which takes
a closure or
Action
as a parameter. - The convention methods added to the project by the plugins. A plugin can add properties and method to
a project through the project's
Convention
object. - The tasks of the project. A method is added for each task, using the name of the task as the method name and
taking a single closure or
Action
parameter. The method calls theTask.configure(groovy.lang.Closure)
method for the associated task with the provided closure. For example, if the project has a task calledcompile
, then a method is added with the following signature:void compile(Closure configureClosure)
. - The methods of the parent project, recursively up to the root project.
- A property of the project whose value is a closure. The closure is treated as a method and called with the provided parameters. The property is located as described above.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_BUILD_DIR_NAME
The default build directory name.static java.lang.String
DEFAULT_BUILD_FILE
The default project build file name.static java.lang.String
DEFAULT_STATUS
static java.lang.String
DEFAULT_VERSION
static java.lang.String
GRADLE_PROPERTIES
static java.lang.String
PATH_SEPARATOR
The hierarchy separator for project and task path names.static java.lang.String
SYSTEM_PROP_PREFIX
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description java.lang.String
absoluteProjectPath(java.lang.String path)
Converts a name to an absolute project path, resolving names relative to this project.void
afterEvaluate(Closure closure)
Adds a closure to call immediately after this project is evaluated.void
afterEvaluate(Action<? super Project> action)
Adds an action to call immediately after this project is evaluated.void
allprojects(Closure configureClosure)
Configures this project and each of its sub-projects.void
allprojects(Action<? super Project> action)
Configures this project and each of its sub-projects.AntBuilder
ant(Closure configureClosure)
Executes the given closure against theAntBuilder
for this project.AntBuilder
ant(Action<? super AntBuilder> configureAction)
Executes the given action against theAntBuilder
for this project.void
artifacts(Closure configureClosure)
Configures the published artifacts for this project.void
artifacts(Action<? super ArtifactHandler> configureAction)
Configures the published artifacts for this project.void
beforeEvaluate(Closure closure)
Adds a closure to call immediately before this project is evaluated.void
beforeEvaluate(Action<? super Project> action)
Adds an action to call immediately before this project is evaluated.void
buildscript(Closure configureClosure)
Configures the build script classpath for this project.void
components(Action<? super SoftwareComponentContainer> configuration)
Configures software components.void
configurations(Closure configureClosure)
Configures the dependency configurations for this project.java.lang.Iterable<?>
configure(java.lang.Iterable<?> objects, Closure configureClosure)
Configures a collection of objects via a closure.<T> java.lang.Iterable<T>
configure(java.lang.Iterable<T> objects, Action<? super T> configureAction)
Configures a collection of objects via an action.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.<T> NamedDomainObjectContainer<T>
container(java.lang.Class<T> type)
Creates a container for managing named objects of the specified type.<T> NamedDomainObjectContainer<T>
container(java.lang.Class<T> type, Closure factoryClosure)
Creates a container for managing named objects of the specified type.<T> NamedDomainObjectContainer<T>
container(java.lang.Class<T> type, NamedDomainObjectFactory<T> factory)
Creates a container for managing named objects of the specified type.WorkResult
copy(Closure closure)
Copies the specified files.WorkResult
copy(Action<? super CopySpec> action)
Copies the specified files.CopySpec
copySpec()
Creates aCopySpec
which can later be used to copy files or create an archive.CopySpec
copySpec(Closure closure)
Creates aCopySpec
which can later be used to copy files or create an archive.CopySpec
copySpec(Action<? super CopySpec> action)
Creates aCopySpec
which can later be used to copy files or create an archive.AntBuilder
createAntBuilder()
Creates an additionalAntBuilder
for this project.void
defaultTasks(java.lang.String... defaultTasks)
Sets the names of the default tasks of this project.boolean
delete(java.lang.Object... paths)
Deletes files and directories.WorkResult
delete(Action<? super DeleteSpec> action)
Deletes the specified files.void
dependencies(Closure configureClosure)
Configures the dependencies for this project.void
dependencyLocking(Action<? super DependencyLockingHandler> configuration)
Configures dependency lockingint
depthCompare(Project otherProject)
Compares the nesting level of this project with another project of the multi-project hierarchy.Project
evaluationDependsOn(java.lang.String path)
Declares that this project has an evaluation dependency on the project with the given path.void
evaluationDependsOnChildren()
Declares that this project has an evaluation dependency on each of its child projects.ExecResult
exec(Closure closure)
Deprecated.Since 8.11.ExecResult
exec(Action<? super ExecSpec> action)
Deprecated.Since 8.11.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 aConfigurableFileCollection
containing the given files.ConfigurableFileCollection
files(java.lang.Object paths, Closure configureClosure)
Creates a newConfigurableFileCollection
using the given paths.ConfigurableFileCollection
files(java.lang.Object paths, Action<? super ConfigurableFileCollection> configureAction)
Creates a newConfigurableFileCollection
using the given paths.ConfigurableFileTree
fileTree(java.lang.Object baseDir)
Creates a newConfigurableFileTree
using the given base directory.ConfigurableFileTree
fileTree(java.lang.Object baseDir, Closure configureClosure)
Creates a newConfigurableFileTree
using the given base directory.ConfigurableFileTree
fileTree(java.lang.Object baseDir, Action<? super ConfigurableFileTree> configureAction)
Creates a newConfigurableFileTree
using the given base directory.ConfigurableFileTree
fileTree(java.util.Map<java.lang.String,?> args)
Creates a newConfigurableFileTree
using the provided map of arguments.Project
findProject(java.lang.String path)
Locates a project by path.java.lang.Object
findProperty(java.lang.String propertyName)
Returns the value of the given property or null if not found.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 theAntBuilder
for this project.ArtifactHandler
getArtifacts()
Returns a handler for assigning artifacts produced by the project to configurations.java.io.File
getBuildDir()
Deprecated.UsegetLayout().getBuildDirectory()
insteadjava.io.File
getBuildFile()
The build script for this project.ScriptHandler
getBuildscript()
Returns the build script handler for this project.java.lang.String
getBuildTreePath()
Returns a path to the project for the full build tree.java.util.Map<java.lang.String,Project>
getChildProjects()
Returns the direct children of this project.SoftwareComponentContainer
getComponents()
Returns the software components produced by this project.ConfigurationContainer
getConfigurations()
Returns the configurations of this project.Convention
getConvention()
Deprecated.The concept of conventions is deprecated.java.util.List<java.lang.String>
getDefaultTasks()
Returns the names of the default tasks of this project.DependencyHandler
getDependencies()
Returns the dependency handler of this project.DependencyFactory
getDependencyFactory()
Provides access to methods to create various kinds ofDependency
instances.DependencyLockingHandler
getDependencyLocking()
Provides access to configuring dependency lockingint
getDepth()
Returns the nesting level of a project in a multi-project hierarchy.java.lang.String
getDescription()
Returns the description of this project, if any.java.lang.String
getDisplayName()
Returns a human-consumable display name for this project.ExtensionContainer
getExtensions()
Allows adding DSL extensions to the project.Gradle
getGradle()
Returns theGradle
invocation which this project belongs to.java.lang.Object
getGroup()
Returns the group of this project.IsolatedProject
getIsolated()
Returns an immutable view of this project, safe for use with isolated projects.ProjectLayout
getLayout()
Provides access to various important directories for this project.Logger
getLogger()
Returns the logger for this project.LoggingManager
getLogging()
Returns theLoggingManager
which can be used to receive logging and to control the standard output/error capture for this project's build script.java.lang.String
getName()
Returns the name of this project.InputNormalizationHandler
getNormalization()
Provides access to configuring input normalization.ObjectFactory
getObjects()
Provides access to methods to create various kinds of model objects.Project
getParent()
Returns the parent project of this project, if any.java.lang.String
getPath()
Returns the path of this project.Project
getProject()
Returns this project.java.io.File
getProjectDir()
The directory containing the project build file.java.util.Map<java.lang.String,?>
getProperties()
Returns the properties of this project.ProviderFactory
getProviders()
Provides access to methods to create various kinds ofProvider
instances.RepositoryHandler
getRepositories()
Returns a handler to create repositories which are used for retrieving dependencies and uploading artifacts produced by the project.ResourceHandler
getResources()
Provides access to resource-specific utility methods, for example factory methods that create various resources.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.ProjectState
getState()
Returns the evaluation state of this project.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.ExecResult
javaexec(Closure closure)
Deprecated.Since 8.11.ExecResult
javaexec(Action<? super JavaExecSpec> action)
Deprecated.Since 8.11.java.io.File
mkdir(java.lang.Object path)
Creates a directory and returns a file pointing to it.void
normalization(Action<? super InputNormalizationHandler> configuration)
Configures input normalization.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.Project
project(java.lang.String path, Action<? super Project> configureAction)
Locates a project by path and configures it using the given action.java.lang.Object
property(java.lang.String propertyName)
Returns the value of the given property.<T> Provider<T>
provider(java.util.concurrent.Callable<? extends @Nullable T> value)
Creates aProvider
implementation based on the provided value.java.lang.String
relativePath(java.lang.Object path)
Returns the relative path from the project directory to the given path.java.lang.String
relativeProjectPath(java.lang.String path)
Converts a name to a project path relative to this project.void
repositories(Closure configureClosure)
Configures the repositories for this project.void
setBuildDir(java.io.File path)
Deprecated.UsegetLayout().getBuildDirectory()
and set theDirectoryProperty
void
setBuildDir(java.lang.Object path)
Deprecated.UsegetLayout().getBuildDirectory()
and set theDirectoryProperty
void
setDefaultTasks(java.util.List<java.lang.String> defaultTasks)
Sets the names of the default tasks of this project.void
setDescription(java.lang.String description)
Sets a description for this project.void
setGroup(java.lang.Object group)
Sets the group of this project.void
setProperty(java.lang.String name, java.lang.Object value)
Sets a property of this project.void
setStatus(java.lang.Object status)
Sets the status of this project.void
setVersion(java.lang.Object version)
Sets the version of this project.void
subprojects(Closure configureClosure)
Configures the sub-projects of this project.void
subprojects(Action<? super Project> action)
Configures the sub-projects of this projectWorkResult
sync(Action<? super SyncSpec> action)
Synchronizes the contents of a destination directory with some source directories and files.FileTree
tarTree(java.lang.Object tarPath)
Creates a newFileTree
which contains the contents of the given TAR file.Task
task(java.lang.String name)
Creates aTask
with the given name and adds it to this project.Task
task(java.lang.String name, Closure configureClosure)
Creates aTask
with the given name and adds it to this project.Task
task(java.lang.String name, Action<? super Task> configureAction)
Creates aTask
with the given name and adds it to this project.Task
task(java.util.Map<java.lang.String,?> args, java.lang.String name)
Creates aTask
with the given name and adds it to this project.Task
task(java.util.Map<java.lang.String,?> args, java.lang.String name, Closure configureClosure)
Creates aTask
with the given name and adds it to this project.java.net.URI
uri(java.lang.Object path)
Resolves a file path to a URI, relative to the project directory of this project.FileTree
zipTree(java.lang.Object zipPath)
Creates a newFileTree
which contains the contents of the given ZIP file.-
Methods inherited from interface org.gradle.api.plugins.PluginAware
apply, apply, apply, getPluginManager, getPlugins
-
-
-
-
Field Detail
-
DEFAULT_BUILD_FILE
static final java.lang.String DEFAULT_BUILD_FILE
The default project build file name.- See Also:
- Constant Field Values
-
PATH_SEPARATOR
static final java.lang.String PATH_SEPARATOR
The hierarchy separator for project and task path names.- See Also:
- Constant Field Values
-
DEFAULT_BUILD_DIR_NAME
static final java.lang.String DEFAULT_BUILD_DIR_NAME
The default build directory name.- See Also:
- Constant Field Values
-
GRADLE_PROPERTIES
static final java.lang.String GRADLE_PROPERTIES
- See Also:
- Constant Field Values
-
SYSTEM_PROP_PREFIX
static final java.lang.String SYSTEM_PROP_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_VERSION
static final java.lang.String DEFAULT_VERSION
- See Also:
- Constant Field Values
-
DEFAULT_STATUS
static final java.lang.String DEFAULT_STATUS
- See Also:
- Constant Field Values
-
-
Method Detail
-
getRootProject
Project getRootProject()
Returns the root project for the hierarchy that this project belongs to. In the case of a single-project build, this method returns this project.
- Returns:
- The root project. Never returns null.
-
getRootDir
java.io.File getRootDir()
Returns the root directory of this project. The root directory is the project directory of the root project.
- Returns:
- The root directory. Never returns null.
-
getBuildDir
@Deprecated java.io.File getBuildDir()
Deprecated.UsegetLayout().getBuildDirectory()
insteadReturns 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
- Returns:
- The build directory. Never returns null.
-
setBuildDir
@Deprecated void setBuildDir(java.io.File path)
Deprecated.UsegetLayout().getBuildDirectory()
and set theDirectoryProperty
Sets the build directory of this project. The build directory is the directory which all artifacts are generated into.
- Parameters:
path
- The build directory- Since:
- 4.0
-
setBuildDir
@Deprecated void setBuildDir(java.lang.Object path)
Deprecated.UsegetLayout().getBuildDirectory()
and set theDirectoryProperty
Sets the build directory of this project. The build directory is the directory which all artifacts are generated into. The path parameter is evaluated as described for
file(Object)
. This mean you can use, amongst other things, a relative or absolute path or File object to specify the build directory.- Parameters:
path
- The build directory. This is evaluated as perfile(Object)
-
getBuildFile
java.io.File getBuildFile()
The build script for this project.If the file exists, it will be evaluated against this project when this project is configured.
- Returns:
- the build script for this project.
-
getParent
@Nullable Project getParent()
Returns the parent project of this project, if any.
- Returns:
- The parent project, or null if this is the root project.
-
getName
java.lang.String getName()
Returns the name of this project. The project's name is not necessarily unique within a project hierarchy. You should use the
getPath()
method for a unique identifier for the project. If the root project is unnamed and is located on a file system root it will have a randomly-generated name- Returns:
- The name of this project. Never return null.
-
getDisplayName
java.lang.String getDisplayName()
Returns a human-consumable display name for this project.
-
getDescription
@Nullable java.lang.String getDescription()
Returns the description of this project, if any.- Returns:
- the description. May return null.
-
setDescription
void setDescription(@Nullable java.lang.String description)
Sets a description for this project.- Parameters:
description
- The description of the project. Might be null.
-
getGroup
java.lang.Object getGroup()
Returns the group of this project. Gradle always uses the
toString()
value of the group. The group defaults to the path with dots as separators.- Returns:
- The group of this project. Never returns null.
-
setGroup
void setGroup(java.lang.Object group)
Sets the group of this project.
- Parameters:
group
- The group of this project. Must not be null.
-
getVersion
java.lang.Object getVersion()
Returns the version of this project. Gradle always uses the
toString()
value of the version. The version defaults to "unspecified".- Returns:
- The version of this project. Never returns null.
-
setVersion
void setVersion(java.lang.Object version)
Sets the version of this project.
- Parameters:
version
- The version of this project. Must not be null.
-
getStatus
java.lang.Object getStatus()
Returns the status of this project. Gradle always uses the
toString()
value of the status. The status defaults to "release".The status of the project is only relevant, if you upload libraries together with a module descriptor. The status specified here, will be part of this module descriptor.
- Returns:
- The status of this project. Never returns null.
-
setStatus
void setStatus(java.lang.Object status)
Sets the status of this project.- Parameters:
status
- The status. Must not be null.
-
getChildProjects
java.util.Map<java.lang.String,Project> getChildProjects()
Returns the direct children of this project.
- Returns:
- A map from child project name to child project. Returns an empty map if this project does not have any children.
-
setProperty
void setProperty(java.lang.String name, @Nullable java.lang.Object value) throws MissingPropertyException
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.
- The project object itself. For example, the
rootDir
project property. - The project's
Convention
object. For example, thesrcRootName
java plugin property. - The project's extra properties.
MissingPropertyException
is thrown.- Parameters:
name
- The name of the propertyvalue
- The value of the property- Throws:
MissingPropertyException
- The project object itself. For example, the
-
getProject
Project getProject()
Returns this project. This method is useful in build files to explicitly access project properties and methods. For example, using
project.name
can express your intent better than usingname
. This method also allows you to access project properties from a scope where the property may be hidden, such as, for example, from a method or closure.- Returns:
- This project. Never returns null.
-
getIsolated
@Incubating IsolatedProject getIsolated()
Returns an immutable view of this project, safe for use with isolated projects.
- Returns:
- This project as an
IsolatedProject
. Never returns null. - Since:
- 8.8
-
getAllprojects
java.util.Set<Project> getAllprojects()
Returns the set containing this project and its subprojects.
- Returns:
- The set of projects.
-
getSubprojects
java.util.Set<Project> getSubprojects()
Returns the set containing the subprojects of this project.
- Returns:
- The set of projects. Returns an empty set if this project has no subprojects.
-
task
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 callingtask(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 properties for more details
If a task with the given name already exists in this project, an exception is thrown.
- Parameters:
name
- The name of the task to be created- Returns:
- The newly created task object
- Throws:
InvalidUserDataException
- If a task with the given name already exists in this project.
-
task
Task task(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:Permitted map keys 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 Action
to add to the task.null
"description"
A description of the task. null
"group"
A task group which this task belongs to. null
After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project and the
override
option is not set to true, an exception is thrown.- Parameters:
args
- The task creation options.name
- The name of the task to be created- Returns:
- The newly created task object
- Throws:
InvalidUserDataException
- If a task with the given name already exists in this project.
-
task
Task task(java.util.Map<java.lang.String,?> args, java.lang.String name, Closure configureClosure)
Creates a
Task
with the given name and adds it to this project. Before the task is returned, the given closure is executed to configure the task. A map of creation options can be passed to this method to control how the task is created. Seetask(java.util.Map, String)
for the available options.After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
If a task with the given name already exists in this project and the
override
option is not set to true, an exception is thrown.- Parameters:
args
- The task creation options.name
- The name of the task to be createdconfigureClosure
- The closure to use to configure the created task.- Returns:
- The newly created task object
- Throws:
InvalidUserDataException
- If a task with the given name already exists in this project.
-
task
Task task(java.lang.String name, @DelegatesTo(Task.class) Closure configureClosure)
Creates a
Task
with the given name and adds it to this project. Before the task is returned, the given closure is executed to configure the task.After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
- Parameters:
name
- The name of the task to be createdconfigureClosure
- The closure to use to configure the created task.- Returns:
- The newly created task object
- Throws:
InvalidUserDataException
- If a task with the given name already exists in this project.
-
task
Task task(java.lang.String name, Action<? super Task> configureAction)
Creates a
Task
with the given name and adds it to this project. Before the task is returned, the given action is executed to configure the task.After the task is added to the project, it is made available as a property of the project, so that you can reference the task by name in your build file. See here for more details
- Parameters:
name
- The name of the task to be createdconfigureAction
- The action to use to configure the created task.- Returns:
- The newly created task object
- Throws:
InvalidUserDataException
- If a task with the given name already exists in this project.- Since:
- 4.10
- See Also:
NamedDomainObjectContainer.create(String, Action)
-
getPath
java.lang.String getPath()
Returns the path of this project. The path is the fully qualified name of the project.
- Returns:
- The path. Never returns null.
-
getBuildTreePath
@Incubating java.lang.String getBuildTreePath()
Returns a path to the project for the full build tree.- Returns:
- The build tree path
- Since:
- 8.3
-
getDefaultTasks
java.util.List<java.lang.String> getDefaultTasks()
Returns the names of the default tasks of this project. These are used when no tasks names are provided when starting the build.
- Returns:
- The default task names. Returns an empty list if this project has no default tasks.
-
setDefaultTasks
void setDefaultTasks(java.util.List<java.lang.String> defaultTasks)
Sets the names of the default tasks of this project. These are used when no tasks names are provided when starting the build.
- Parameters:
defaultTasks
- The default task names.
-
defaultTasks
void defaultTasks(java.lang.String... defaultTasks)
Sets the names of the default tasks of this project. These are used when no tasks names are provided when starting the build.
- Parameters:
defaultTasks
- The default task names.
-
evaluationDependsOn
Project evaluationDependsOn(java.lang.String path) throws UnknownProjectException
Declares that this project has an evaluation dependency on the project with the given path.
- Parameters:
path
- The path of the project which this project depends on.- Returns:
- The project which this project depends on.
- Throws:
UnknownProjectException
- If no project with the given path exists.
-
evaluationDependsOnChildren
void evaluationDependsOnChildren()
Declares that this project has an evaluation dependency on each of its child projects.
-
findProject
@Nullable Project findProject(java.lang.String path)
Locates a project by path. If the path is relative, it is interpreted relative to this project.
- Parameters:
path
- The path.- Returns:
- The project with the given path. Returns null if no such project exists.
-
project
Project project(java.lang.String path) throws UnknownProjectException
Locates a project by path. If the path is relative, it is interpreted relative to this project.
- Parameters:
path
- The path.- Returns:
- The project with the given path. Never returns null.
- Throws:
UnknownProjectException
- If no project with the given path exists.
-
project
Project project(java.lang.String path, @DelegatesTo(Project.class) Closure configureClosure)
Locates a project by path and configures it using the given closure. If the path is relative, it is interpreted relative to this project. The target project is passed to the closure as the closure's delegate.
- Parameters:
path
- The path.configureClosure
- The closure to use to configure the project.- Returns:
- The project with the given path. Never returns null.
- Throws:
UnknownProjectException
- If no project with the given path exists.
-
project
Project project(java.lang.String path, Action<? super Project> configureAction)
Locates a project by path and configures it using the given action. If the path is relative, it is interpreted relative to this project.
- Parameters:
path
- The path.configureAction
- The action to use to configure the project.- Returns:
- The project with the given path. Never returns null.
- Throws:
UnknownProjectException
- If no project with the given path exists.- Since:
- 3.4
-
getAllTasks
java.util.Map<Project,java.util.Set<Task>> getAllTasks(boolean recursive)
Returns a map of the tasks contained in this project, and optionally its subprojects.
- Parameters:
recursive
- If true, returns the tasks of this project and its subprojects. If false, returns the tasks of just this project.- Returns:
- A map from project to a set of tasks.
-
getTasksByName
java.util.Set<Task> getTasksByName(java.lang.String name, boolean recursive)
Returns the set of tasks with the given name contained in this project, and optionally its subprojects. NOTE: This is an expensive operation since it requires all projects to be configured.
- Parameters:
name
- The name of the task to locate.recursive
- If true, returns the tasks of this project and its subprojects. If false, returns the tasks of just this project.- Returns:
- The set of tasks. Returns an empty set if no such tasks exist in this project.
-
getProjectDir
java.io.File getProjectDir()
The directory containing the project build file.
- Returns:
- The project directory. Never returns null.
-
file
java.io.File file(java.lang.Object path)
Resolves a file path relative to the project directory of this project. This method converts the supplied path based on its type:
- A
CharSequence
, includingString
orGString
. Interpreted relative to the project directory. A string that starts withfile:
is treated as a file URL. - A
File
. If the file is an absolute file, it is returned as is. Otherwise, the file's path is interpreted relative to the project directory. - A
Path
. The path must be associated with the default provider and is treated the same way as an instance ofFile
. - A
URI
orURL
. The URL's path is interpreted as the file path. Onlyfile:
URLs are supported. - A
Directory
orRegularFile
. - A
Provider
of any supported type. The provider's value is resolved recursively. - A
TextResource
. - A Groovy
Closure
or Kotlin function that returns any supported type. The closure's return value is resolved recursively. - A
Callable
that returns any supported type. The callable's return value is resolved recursively.
- Parameters:
path
- The object to resolve as a File.- Returns:
- The resolved file. Never returns null.
- 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.- Parameters:
path
- An object which toString method value is interpreted as a relative path to the project directory.validation
- The validation to perform on the file.- Returns:
- The resolved file. Never returns null.
- Throws:
InvalidUserDataException
- When the file does not meet the given validation constraint.
-
uri
java.net.URI uri(java.lang.Object path)
Resolves a file path to a URI, relative to the project directory of this project. Evaluates the provided path object as described for
file(Object)
, with the exception that any URI scheme is supported, not just 'file:' URIs.- Parameters:
path
- The object to resolve as a URI.- Returns:
- The resolved URI. Never returns null.
-
relativePath
java.lang.String relativePath(java.lang.Object path)
Returns the relative path from the project directory to the given path. The given path object is (logically) resolved as described for
file(Object)
, from which a relative path is calculated.- Parameters:
path
- The path to convert to a relative path.- Returns:
- The relative path. Never returns null.
- Throws:
java.lang.IllegalArgumentException
- If the given path cannot be relativized against the project directory.
-
files
ConfigurableFileCollection files(java.lang.Object... paths)
Returns a
ConfigurableFileCollection
containing the given files. You can pass any of the following types to this method:- A
CharSequence
, includingString
orGString
. Interpreted relative to the project directory, as perfile(Object)
. A string that starts withfile:
is treated as a file URL. - A
File
. Interpreted relative to the project directory, as perfile(Object)
. - A
Path
, as perfile(Object)
. - A
URI
orURL
. The URL's path is interpreted as a file path. Onlyfile:
URLs are supported. - A
Directory
orRegularFile
. - A
Collection
,Iterable
, or an array that contains objects of any supported type. The elements of the collection are recursively converted to files. - A
FileCollection
. The contents of the collection are included in the returned collection. - A
FileTree
orDirectoryTree
. The contents of the tree are included in the returned collection. - A
Provider
of any supported type. The provider's value is recursively converted to files. If the provider represents an output of a task, that task is executed if the file collection is used as an input to another task. - A
Callable
that returns any supported type. The return value of thecall()
method is recursively converted to files. Anull
return value is treated as an empty collection. - A Groovy
Closure
or Kotlin function that returns any of the types listed here. The return value of the closure is recursively converted to files. Anull
return value is treated as an empty collection. - A
Task
. Converted to the task's output files. The task is executed if the file collection is used as an input to another task. - A
TaskOutputs
. Converted to the output files the related task. The task is executed if the file collection is used as an input to another task. - Anything else is treated as an error.
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.
The returned file collection maintains the details of the tasks that produce the files, so that these tasks are executed if this file collection is used as an input to some task.
This method can also be used to create an empty collection, which can later be mutated to add elements.
- Parameters:
paths
- The paths to the files. May be empty.- Returns:
- The file collection. Never returns null.
- A
-
files
ConfigurableFileCollection files(java.lang.Object paths, @DelegatesTo(ConfigurableFileCollection.class) Closure configureClosure)
Creates a new
ConfigurableFileCollection
using the given paths. The paths are evaluated as perfiles(Object...)
. The file collection is configured using the given closure. The file collection is passed to the closure as its delegate. Example:files "$buildDir/classes" { builtBy 'compile' }
The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.
- Parameters:
paths
- The contents of the file collection. Evaluated as perfiles(Object...)
.configureClosure
- The closure to use to configure the file collection.- Returns:
- the configured file tree. Never returns null.
-
files
ConfigurableFileCollection files(java.lang.Object paths, Action<? super ConfigurableFileCollection> configureAction)
Creates a new
ConfigurableFileCollection
using the given paths. The paths are evaluated as perfiles(Object...)
. The file collection is configured using the given action. Example:files "$buildDir/classes" { builtBy 'compile' }
The returned file collection is lazy, so that the paths are evaluated only when the contents of the file collection are queried. The file collection is also live, so that it evaluates the above each time the contents of the collection is queried.
- Parameters:
paths
- The contents of the file collection. Evaluated as perfiles(Object...)
.configureAction
- The action to use to configure the file collection.- Returns:
- the configured file tree. Never returns null.
- Since:
- 3.5
-
fileTree
ConfigurableFileTree fileTree(java.lang.Object baseDir)
Creates a new
ConfigurableFileTree
using the given base directory. The given baseDir path is evaluated as perfile(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.
def myTree = fileTree("src") myTree.include "**/*.java" myTree.builtBy "someTask" task copy(type: Copy) { from myTree }
The order of the files in a
FileTree
is not stable, even on a single computer.- Parameters:
baseDir
- The base directory of the file tree. Evaluated as perfile(Object)
.- Returns:
- the file tree. Never returns null.
-
fileTree
ConfigurableFileTree fileTree(java.lang.Object baseDir, @DelegatesTo(ConfigurableFileTree.class) Closure configureClosure)
Creates a new
ConfigurableFileTree
using the given base directory. The given baseDir path is evaluated as perfile(Object)
. The closure will be used to configure the new file tree. The file tree is passed to the closure as its delegate. Example:def myTree = fileTree('src') { exclude '**/.data/**' builtBy 'someTask' } task copy(type: Copy) { from myTree }
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.
The order of the files in a
FileTree
is not stable, even on a single computer.- Parameters:
baseDir
- The base directory of the file tree. Evaluated as perfile(Object)
.configureClosure
- Closure to configure theConfigurableFileTree
object.- Returns:
- the configured file tree. Never returns null.
-
fileTree
ConfigurableFileTree fileTree(java.lang.Object baseDir, Action<? super ConfigurableFileTree> configureAction)
Creates a new
ConfigurableFileTree
using the given base directory. The given baseDir path is evaluated as perfile(Object)
. The action will be used to configure the new file tree. Example:def myTree = fileTree('src') { exclude '**/.data/**' builtBy 'someTask' } task copy(type: Copy) { from myTree }
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.
The order of the files in a
FileTree
is not stable, even on a single computer.- Parameters:
baseDir
- The base directory of the file tree. Evaluated as perfile(Object)
.configureAction
- Action to configure theConfigurableFileTree
object.- Returns:
- the configured file tree. Never returns null.
- Since:
- 3.5
-
fileTree
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:def myTree = fileTree(dir:'src', excludes:['**/ignore/**', '**/.data/**']) task copy(type: Copy) { from myTree }
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.
The order of the files in a
FileTree
is not stable, even on a single computer.- Parameters:
args
- map of property assignments toConfigurableFileTree
object- Returns:
- the configured file tree. Never returns null.
-
zipTree
FileTree zipTree(java.lang.Object zipPath)
Creates a new
FileTree
which contains the contents of the given ZIP file. The given zipPath path is evaluated as perfile(Object)
. You can combine this method with thecopy(Action)
method to unzip a ZIP file.The returned file tree is lazy, so that it scans for files only when the contents of the file tree are queried. The file tree is also live, so that it scans for files each time the contents of the file tree are queried.
- Parameters:
zipPath
- The ZIP file. Evaluated as perfile(Object)
.- Returns:
- the file tree. Never returns null.
-
tarTree
FileTree tarTree(java.lang.Object tarPath)
Creates a newFileTree
which contains the contents of the given TAR file. The given tarPath path can be:- an instance of
Resource
- any other object is evaluated as per
file(Object)
Unless custom implementation of resources is passed, the tar tree attempts to guess the compression based on the file extension.
You can combine this method with the
copy(Action)
method to untar a TAR file:task untar(type: Copy) { from tarTree('someCompressedTar.gzip') //tar tree attempts to guess the compression based on the file extension //however if you must specify the compression explicitly you can: from tarTree(resources.gzip('someTar.ext')) //in case you work with unconventionally compressed tars //you can provide your own implementation of a ReadableResource: //from tarTree(yourOwnResource as ReadableResource) into 'dest' }
- Parameters:
tarPath
- The TAR file or an instance ofResource
.- Returns:
- the file tree. Never returns null.
- an instance of
-
provider
<T> Provider<T> provider(java.util.concurrent.Callable<? extends @Nullable T> value)
Creates aProvider
implementation based on the provided value.The provider is live and will call the
Callable
each time its value is queried. TheCallable
may returnnull
, in which case the provider is considered to have no value.- Parameters:
value
- TheCallable
use to calculate the value.- Returns:
- The provider. Never returns null.
- Since:
- 4.0
- See Also:
ProviderFactory.provider(Callable)
-
getProviders
ProviderFactory getProviders()
Provides access to methods to create various kinds ofProvider
instances.- Since:
- 4.0
-
getObjects
ObjectFactory getObjects()
Provides access to methods to create various kinds of model objects.- Since:
- 4.0
-
getLayout
ProjectLayout getLayout()
Provides access to various important directories for this project.- Since:
- 4.1
-
mkdir
java.io.File mkdir(java.lang.Object path)
Creates a directory and returns a file pointing to it.- Parameters:
path
- The path for the directory to be created. Evaluated as perfile(Object)
.- Returns:
- the created directory
- Throws:
InvalidUserDataException
- If the path points to an existing file.
-
delete
boolean delete(java.lang.Object... paths)
Deletes files and directories.This will not follow symlinks. If you need to follow symlinks too use
delete(Action)
.- Parameters:
paths
- Any type of object accepted byfiles(Object...)
- Returns:
- true if anything got deleted, false otherwise
-
delete
WorkResult delete(Action<? super DeleteSpec> action)
Deletes the specified files. The given action is used to configure aDeleteSpec
, which is then used to delete the files.Example:
project.delete { delete 'somefile' followSymlinks = true }
- Parameters:
action
- Action to configure the DeleteSpec- Returns:
WorkResult
that can be used to check if delete did any work.
-
javaexec
@Deprecated ExecResult javaexec(@DelegatesTo(JavaExecSpec.class) Closure closure)
Deprecated.Since 8.11. This method will be removed in Gradle 9.0. UseExecOperations.javaexec(Action)
orProviderFactory.javaexec(Action)
instead.Executes a Java main class. The closure configures aJavaExecSpec
.- Parameters:
closure
- The closure for configuring the execution.- Returns:
- the result of the execution
-
javaexec
@Deprecated ExecResult javaexec(Action<? super JavaExecSpec> action)
Deprecated.Since 8.11. This method will be removed in Gradle 9.0. UseExecOperations.javaexec(Action)
orProviderFactory.javaexec(Action)
instead.Executes an external Java process.The given action configures a
JavaExecSpec
, which is used to launch the process. This method blocks until the process terminates, with its result being returned.- Parameters:
action
- The action for configuring the execution.- Returns:
- the result of the execution
-
exec
@Deprecated ExecResult exec(@DelegatesTo(ExecSpec.class) Closure closure)
Deprecated.Since 8.11. This method will be removed in Gradle 9.0. UseExecOperations.exec(Action)
orProviderFactory.exec(Action)
instead.Executes an external command. The closure configures aExecSpec
.- Parameters:
closure
- The closure for configuring the execution.- Returns:
- the result of the execution
-
exec
@Deprecated ExecResult exec(Action<? super ExecSpec> action)
Deprecated.Since 8.11. This method will be removed in Gradle 9.0. UseExecOperations.exec(Action)
orProviderFactory.exec(Action)
instead.Executes an external command.The given action configures a
ExecSpec
, which is used to launch the process. This method blocks until the process terminates, with its result being returned.- Parameters:
action
- The action for configuring the execution.- Returns:
- the result of the execution
-
absoluteProjectPath
java.lang.String absoluteProjectPath(java.lang.String path)
Converts a name to an absolute project path, resolving names relative to this project.
- Parameters:
path
- The path to convert.- Returns:
- The absolute path.
-
relativeProjectPath
java.lang.String relativeProjectPath(java.lang.String path)
Converts a name to a project path relative to this project.
- Parameters:
path
- The path to convert.- Returns:
- The relative path.
-
getAnt
AntBuilder getAnt()
Returns the
AntBuilder
for this project. You can use this in your build file to execute ant tasks. See example below.task printChecksum { doLast { ant { //using ant checksum task to store the file checksum in the checksumOut ant property checksum(property: 'checksumOut', file: 'someFile.txt') //we can refer to the ant property created by checksum task: println "The checksum is: " + checksumOut } //we can refer to the ant property later as well: println "I just love to print checksums: " + ant.checksumOut } }
Consider following example of ant target:<target name='printChecksum'> <checksum property='checksumOut'> <fileset dir='.'> <include name='agile.txt'/> </fileset> </checksum> <echo>The checksum is: ${checksumOut}</echo> </target>
Here's how it would look like in gradle. Observe how the ant XML is represented in groovy by the ant buildertask printChecksum { doLast { ant { checksum(property: 'checksumOut') { fileset(dir: '.') { include name: 'agile1.txt' } } } logger.lifecycle("The checksum is $ant.checksumOut") } }
- Returns:
- The
AntBuilder
for this project. Never returns null.
-
createAntBuilder
AntBuilder createAntBuilder()
Creates an additional
AntBuilder
for this project. You can use this in your build file to execute ant tasks.- Returns:
- Creates an
AntBuilder
for this project. Never returns null. - See Also:
getAnt()
-
ant
AntBuilder ant(@DelegatesTo(AntBuilder.class) Closure configureClosure)
Executes the given closure against the
AntBuilder
for this project. You can use this in your build file to execute ant tasks. TheAntBuild
is passed to the closure as the closure's delegate. See example in javadoc forgetAnt()
- Parameters:
configureClosure
- The closure to execute against theAntBuilder
.- Returns:
- The
AntBuilder
. Never returns null.
-
ant
AntBuilder ant(Action<? super AntBuilder> configureAction)
Executes the given action against the
AntBuilder
for this project. You can use this in your build file to execute ant tasks. See example in javadoc forgetAnt()
- Parameters:
configureAction
- The action to execute against theAntBuilder
.- Returns:
- The
AntBuilder
. Never returns null. - Since:
- 3.5
-
getConfigurations
ConfigurationContainer getConfigurations()
Returns the configurations of this project.Examples: See docs for
ConfigurationContainer
- Returns:
- The configuration of this project.
-
configurations
void configurations(Closure configureClosure)
Configures the dependency configurations for this project.
This method executes the given closure against the
ConfigurationContainer
for this project. TheConfigurationContainer
is passed to the closure as the closure's delegate.Examples: See docs for
ConfigurationContainer
- Parameters:
configureClosure
- the closure to use to configure the dependency configurations.
-
getArtifacts
ArtifactHandler getArtifacts()
Returns a handler for assigning artifacts produced by the project to configurations.Examples: See docs for
ArtifactHandler
-
artifacts
void artifacts(@DelegatesTo(ArtifactHandler.class) Closure configureClosure)
Configures the published artifacts for this project.
This method executes the given closure against the
ArtifactHandler
for this project. TheArtifactHandler
is passed to the closure as the closure's delegate.Example:
configurations { //declaring new configuration that will be used to associate with artifacts schema } task schemaJar(type: Jar) { //some imaginary task that creates a jar artifact with the schema } //associating the task that produces the artifact with the configuration artifacts { //configuration name and the task: schema schemaJar }
- Parameters:
configureClosure
- the closure to use to configure the published artifacts.
-
artifacts
void artifacts(Action<? super ArtifactHandler> configureAction)
Configures the published artifacts for this project.
This method executes the given action against the
ArtifactHandler
for this project.Example:
configurations { //declaring new configuration that will be used to associate with artifacts schema } task schemaJar(type: Jar) { //some imaginary task that creates a jar artifact with the schema } //associating the task that produces the artifact with the configuration artifacts { //configuration name and the task: schema schemaJar }
- Parameters:
configureAction
- the action to use to configure the published artifacts.- Since:
- 3.5
-
getConvention
@Deprecated Convention getConvention()
Deprecated.The concept of conventions is deprecated. Use extensions if possible.Returns the
Convention
for this project.You can access this property in your build file using
convention
. You can also access the properties and methods of the convention object as if they were properties and methods of this project. See here for more details- Returns:
- The
Convention
. Never returns null. - See Also:
ExtensionAware.getExtensions()
-
depthCompare
int depthCompare(Project otherProject)
Compares the nesting level of this project with another project of the multi-project hierarchy.
- Parameters:
otherProject
- The project to compare the nesting level with.- Returns:
- a negative integer, zero, or a positive integer as this project has a nesting level less than, equal to, or greater than the specified object.
- See Also:
getDepth()
-
getDepth
int getDepth()
Returns the nesting level of a project in a multi-project hierarchy. For single project builds this is always 0. In a multi-project hierarchy 0 is returned for the root project.
-
getTasks
TaskContainer getTasks()
Returns the tasks of this project.
- Returns:
- the tasks of this project.
-
subprojects
void subprojects(Action<? super Project> action)
Configures the sub-projects of this project
This method executes the given
Action
against the sub-projects of this project.- Parameters:
action
- The action to execute.
-
subprojects
void subprojects(@DelegatesTo(Project.class) Closure configureClosure)
Configures the sub-projects of this project.
This method 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.- Parameters:
configureClosure
- The closure to execute.
-
allprojects
void allprojects(Action<? super Project> action)
Configures this project and each of its sub-projects.
This method executes the given
Action
against this project and each of its sub-projects.- Parameters:
action
- The action to execute.
-
allprojects
void allprojects(@DelegatesTo(Project.class) Closure configureClosure)
Configures this project and each of its sub-projects.
This method executes the given closure against this project and its sub-projects. The target
Project
is passed to the closure as the closure's delegate.- Parameters:
configureClosure
- The closure to execute.
-
beforeEvaluate
void beforeEvaluate(Action<? super Project> action)
Adds an action to call immediately before this project is evaluated.
Passes the project to the action as a parameter. Actions passed to this method execute in the same order they were passed.
If the project has already been evaluated, the action never executes.
If you call this method within a
beforeEvaluate
action, the passed action never executes.- Parameters:
action
- the action to execute.
-
afterEvaluate
void afterEvaluate(Action<? super Project> action)
Adds an action to call immediately after this project is evaluated.
Passes the project to the action as a parameter. Actions passed to this method execute in the same order they were passed. A parent project may add an action to its child projects to further configure those projects based on their state after their build files run.
If the project has already been evaluated, this method fails.
If you call this method within an
afterEvaluate
action, the passed action executes after all previously addedafterEvaluate
actions finish executing.- Parameters:
action
- the action to execute.
-
beforeEvaluate
void beforeEvaluate(Closure closure)
Adds a closure to call immediately before this project is evaluated.
- Parameters:
closure
- The closure to call.- See Also:
beforeEvaluate(Action)
-
afterEvaluate
void afterEvaluate(@DelegatesTo(Project.class) Closure closure)
Adds a closure to call immediately after this project is evaluated.
- Parameters:
closure
- The closure to call.- See Also:
afterEvaluate(Action)
-
hasProperty
boolean hasProperty(java.lang.String propertyName)
Determines if this project has the given property. See here for details of the properties which are available for a project.
- Parameters:
propertyName
- The name of the property to locate.- Returns:
- True if this project has the given property, false otherwise.
-
getProperties
java.util.Map<java.lang.String,?> getProperties()
Returns the properties of this project. See here for details of the properties which are available for a project.
- Returns:
- A map from property name to value.
-
property
@Nullable java.lang.Object property(java.lang.String propertyName) throws MissingPropertyException
Returns the value of the given property. This method locates a property as follows:
- If this project object has a property with the given name, return the value of the property.
- If this project has an extension with the given name, return the extension.
- If this project's convention object has a property with the given name, return the value of the property.
- If this project has an extra property with the given name, return the value of the property.
- If this project has a task with the given name, return the task.
- Search up through this project's ancestor projects for a convention property or extra property with the given name.
- If not found, a
MissingPropertyException
is thrown.
- Parameters:
propertyName
- The name of the property.- Returns:
- The value of the property, possibly null.
- Throws:
MissingPropertyException
- When the given property is unknown.- See Also:
findProperty(String)
-
findProperty
@Nullable java.lang.Object findProperty(java.lang.String propertyName)
Returns the value of the given property or null if not found. This method locates a property as follows:
- If this project object has a property with the given name, return the value of the property.
- If this project has an extension with the given name, return the extension.
- If this project's convention object has a property with the given name, return the value of the property.
- If this project has an extra property with the given name, return the value of the property.
- If this project has a task with the given name, return the task.
- Search up through this project's ancestor projects for a convention property or extra property with the given name.
- If not found, null value is returned.
- Parameters:
propertyName
- The name of the property.- Returns:
- The value of the property, possibly null or null if not found.
- Since:
- 2.13
- See Also:
property(String)
-
getLogger
Logger getLogger()
Returns the logger for this project. You can use this in your build file to write log messages.
- Returns:
- The logger. Never returns null.
-
getGradle
Gradle getGradle()
Returns the
Gradle
invocation which this project belongs to.- Returns:
- The Gradle object. Never returns null.
-
getLogging
LoggingManager getLogging()
Returns theLoggingManager
which can be used to receive logging and to control the standard output/error capture for this project's build script. By default, System.out is redirected to the Gradle logging system at the QUIET log level, and System.err is redirected at the ERROR log level.- Returns:
- the LoggingManager. Never returns null.
-
configure
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() }
The object being configured is also passed to the closure as a parameter, so you can access it explicitly if required:
configure(someObj) { obj -> obj.doThis() }
- Parameters:
object
- The object to configureconfigureClosure
- The closure with configure statements- Returns:
- The configured object
-
configure
java.lang.Iterable<?> configure(java.lang.Iterable<?> objects, Closure configureClosure)
Configures a collection of objects via a closure. This is equivalent to callingconfigure(Object, groovy.lang.Closure)
for each of the given objects.- Parameters:
objects
- The objects to configureconfigureClosure
- The closure with configure statements- Returns:
- The configured objects.
-
configure
<T> java.lang.Iterable<T> configure(java.lang.Iterable<T> objects, Action<? super T> configureAction)
Configures a collection of objects via an action.- Parameters:
objects
- The objects to configureconfigureAction
- The action to apply to each object- Returns:
- The configured objects.
-
getRepositories
RepositoryHandler getRepositories()
Returns a handler to create repositories which are used for retrieving dependencies and uploading artifacts produced by the project.- Returns:
- the repository handler. Never returns null.
-
repositories
void repositories(Closure configureClosure)
Configures the repositories for this project.
This method executes the given closure against the
RepositoryHandler
for this project. TheRepositoryHandler
is passed to the closure as the closure's delegate.- Parameters:
configureClosure
- the closure to use to configure the repositories.
-
getDependencies
DependencyHandler getDependencies()
Returns the dependency handler of this project. The returned dependency handler instance can be used for adding new dependencies. For accessing already declared dependencies, the configurations can be used.Examples: See docs for
DependencyHandler
- Returns:
- the dependency handler. Never returns null.
- See Also:
getConfigurations()
-
dependencies
void dependencies(Closure configureClosure)
Configures the dependencies for this project.
This method executes the given closure against the
DependencyHandler
for this project. TheDependencyHandler
is passed to the closure as the closure's delegate.Examples: See docs for
DependencyHandler
- Parameters:
configureClosure
- the closure to use to configure the dependencies.
-
getDependencyFactory
@Incubating DependencyFactory getDependencyFactory()
Provides access to methods to create various kinds ofDependency
instances.- Returns:
- the dependency factory. Never returns null.
- Since:
- 7.6
-
getBuildscript
ScriptHandler getBuildscript()
Returns the build script handler for this project. You can use this handler to query details about the build script for this project, and manage the classpath used to compile and execute the project's build script.- Returns:
- the classpath handler. Never returns null.
-
buildscript
void buildscript(Closure configureClosure)
Configures the build script classpath for this project.
The given closure is executed against this project's
ScriptHandler
. TheScriptHandler
is passed to the closure as the closure's delegate.- Parameters:
configureClosure
- the closure to use to configure the build script classpath.
-
copy
WorkResult copy(@DelegatesTo(CopySpec.class) Closure closure)
Copies the specified files. The given closure is used to configure aCopySpec
, which is then used to copy the files. Example:copy { from configurations.runtimeClasspath into 'build/deploy/lib' }
Note that CopySpecs can be nested:copy { into 'build/webroot' exclude '**/.svn/**' from('src/main/webapp') { include '**/*.jsp' filter(ReplaceTokens, tokens:[copyright:'2009', version:'2.3.1']) } from('src/main/js') { include '**/*.js' } }
- Parameters:
closure
- Closure to configure the CopySpec- Returns:
WorkResult
that can be used to check if the copy did any work.
-
copy
WorkResult copy(Action<? super CopySpec> action)
Copies the specified files. The given action is used to configure aCopySpec
, which is then used to copy the files.- Parameters:
action
- Action to configure the CopySpec- Returns:
WorkResult
that can be used to check if the copy did any work.- See Also:
copy(Closure)
-
copySpec
CopySpec copySpec(@DelegatesTo(CopySpec.class) Closure closure)
Creates aCopySpec
which can later be used to copy files or create an archive. The given closure is used to configure theCopySpec
before it is returned by this method.def baseSpec = copySpec { from "source" include "**/*.java" } task copy(type: Copy) { into "target" with baseSpec }
- Parameters:
closure
- Closure to configure the CopySpec- Returns:
- The CopySpec
-
copySpec
CopySpec copySpec(Action<? super CopySpec> action)
Creates aCopySpec
which can later be used to copy files or create an archive. The given action is used to configure theCopySpec
before it is returned by this method.- Parameters:
action
- Action to configure the CopySpec- Returns:
- The CopySpec
- See Also:
copySpec(Closure)
-
copySpec
CopySpec copySpec()
Creates aCopySpec
which can later be used to copy files or create an archive.- Returns:
- a newly created copy spec
-
sync
WorkResult sync(Action<? super SyncSpec> action)
Synchronizes the contents of a destination directory with some source directories and files. The given action is used to configure aSyncSpec
, which is then used to synchronize the files.This method is like the
copy(Action)
task, except the destination directory will only contain the files copied. All files that exist in the destination directory will be deleted before copying files, unless a preserve option is specified.Example:
project.sync { from 'my/shared/dependencyDir' into 'build/deps/compile' }
Note that you can preserve output that already exists in the destination directory:project.sync { from 'source' into 'dest' preserve { include 'extraDir/**' include 'dir1/**' exclude 'dir1/extra.txt' } }
- Parameters:
action
- Action to configure the SyncSpec.- Returns:
WorkResult
that can be used to check if the sync did any work.- Since:
- 4.0
-
getState
ProjectState getState()
Returns the evaluation state of this project. You can use this to access information about the evaluation of this project, such as whether it has failed.- Returns:
- the project state. Never returns null.
-
container
<T> NamedDomainObjectContainer<T> container(java.lang.Class<T> type)
Creates a container for managing named objects of the specified type. The specified type must have a public constructor which takes the name as a String parameter.
All objects MUST expose their name as a bean property named "name". The name must be constant for the life of the object.
- Type Parameters:
T
- The type of objects for the container to contain.- Parameters:
type
- The type of objects for the container to contain.- Returns:
- The container.
-
container
<T> NamedDomainObjectContainer<T> container(java.lang.Class<T> type, NamedDomainObjectFactory<T> factory)
Creates a container for managing named objects of the specified type. The given factory is used to create object instances.
All objects MUST expose their name as a bean property named "name". The name must be constant for the life of the object.
- Type Parameters:
T
- The type of objects for the container to contain.- Parameters:
type
- The type of objects for the container to contain.factory
- The factory to use to create object instances.- Returns:
- The container.
-
container
<T> NamedDomainObjectContainer<T> container(java.lang.Class<T> type, Closure factoryClosure)
Creates a container for managing named objects of the specified type. The given closure is used to create object instances. The name of the instance to be created is passed as a parameter to the closure.
All objects MUST expose their name as a bean property named "name". The name must be constant for the life of the object.
- Type Parameters:
T
- The type of objects for the container to contain.- Parameters:
type
- The type of objects for the container to contain.factoryClosure
- The closure to use to create object instances.- Returns:
- The container.
-
getExtensions
ExtensionContainer getExtensions()
Allows adding DSL extensions to the project. Useful for plugin authors.- Specified by:
getExtensions
in interfaceExtensionAware
- Returns:
- Returned instance allows adding DSL extensions to the project
-
getResources
ResourceHandler getResources()
Provides access to resource-specific utility methods, for example factory methods that create various resources.- Returns:
- Returned instance contains various resource-specific utility methods.
-
getComponents
SoftwareComponentContainer getComponents()
Returns the software components produced by this project.- Returns:
- The components for this project.
-
components
@Incubating void components(Action<? super SoftwareComponentContainer> configuration)
Configures software components.- Parameters:
configuration
- Action to configure the software components.- Since:
- 8.1
-
getNormalization
InputNormalizationHandler getNormalization()
Provides access to configuring input normalization.- Since:
- 4.0
-
normalization
void normalization(Action<? super InputNormalizationHandler> configuration)
Configures input normalization.- Since:
- 4.0
-
dependencyLocking
void dependencyLocking(Action<? super DependencyLockingHandler> configuration)
Configures dependency locking- Since:
- 4.8
-
getDependencyLocking
DependencyLockingHandler getDependencyLocking()
Provides access to configuring dependency locking- Since:
- 4.8
-
-