public interface Project extends 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.
このインターフェースは、ビルドファイル内でGradleとやりとりする際、メインで使用するAPIです。Project
から、Gradleの全ての機能にプログラム的にアクセスできます。
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:
Project
と"build.gradle"
ファイルは、1対1の関係性を持ちます。
ビルドの初期化の際に、Gradleは各プロジェクトのビルドに参加しているProject
オブジェクトに、以下に示すような組み付けを行います。
Settings
instance for the build. ビルド用に、Settings
インスタンスを作成します。"settings.gradle"
script, if
present, against the Settings
object to configure it.構成するSettings
オブジェクトに対して、"settings.gradle"
が存在するならば、評価します。Settings
object to create the hierarchy of
Project
instances.Project
インスタンスの階層の作成に、構成したSettings
オブジェクトを使用します。Project
by executing its "build.gradle"
file, if
present, against the project. The project are evaluated in breadth-wise order, such that a project is evaluated
before its child projects. This order can be overridden by calling evaluationDependsOnChildren()
or by adding an
explicit evaluation dependency using evaluationDependsOn(String)
.
最後に、プロジェクトに対して存在するならば、"build.gradle"
ファイルを実行し各Project
を評価します。
プロジェクトは、子プロジェクトより前に評価されるプロジェクトの様に、横方向の順序で評価されます。
This order can be overridden by calling evaluationDependsOnChildren()
or by adding an
explicit evaluation dependency using evaluationDependsOn(String)
.この順序はevaluationDependsOnChildren()
の呼び出しか、evaluationDependsOn(String)
を使用した明示的な評価依存関係の追加によって上書きできます。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
create()
methods on TaskContainer
, such as TaskContainer.create(String)
. You can locate existing
tasks using one of the lookup methods on TaskContainer
, such as TaskCollection.getByName(String)
.
プロジェクトは効果的なTask
オブジェクトのコレクションです。 それぞれのタスクは、クラスのコンパイルや、ユニットテストの実行、WARファイルの圧縮などのような、作業の基本的な一片として動作します。
あなたはTaskContainer.create(String)
のようなTaskContainer
上のcreate()
メソッドの1つを使用し、タスクをプロジェクトに追加します。
あなたはTaskCollection.getByName(String)
のようなTaskContainer
上のルックアップメソッドの1つを使用し、存在するタスクを配置できます。
A project generally has a number of dependencies it needs in order to do its work. Also, a project generally
produces a number of artifacts, which other projects can use. Those dependencies are grouped in configurations, and
can be retrieved and uploaded from repositories. You use the ConfigurationContainer
returned by getConfigurations()
method to manage the configurations. The DependencyHandler
returned by getDependencies()
method to manage the
dependencies. The ArtifactHandler
returned by getArtifacts()
method to
manage the artifacts. The RepositoryHandler
returned by getRepositories()
method to manage the repositories.
一般的なプロジェクトはその動作をするために必要ないくつもの依存性を持っています。さらに、一般的なプロジェクトは他のプロジェクトが使用できるようないくつもの成果物を生成します。
それらの依存性は構成内でグループ化され、リポジトリから回収され、アップロードされる事ができます。
あなたは構成を管理するgetConfigurations()
メソッドから返されたConfigurationContainer
や、依存性を管理するgetDependencies()
メソッドから返されたDependencyHandler
や、成果物を管理するgetArtifacts()
メソッドから返されたArtifactHandler
や、リポジトリを管理するgetRepositories()
メソッドから返されたRepositoryHandler
を使います。
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 can be used to modularise and reuse project configuration.
Plugins can be applied using the apply(java.util.Map)
method, or by using the plugins script block
.
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 associated Project
object. This
means, that you can use any of the methods and properties on the Project
interface directly in your script.
Gradleはプロジェクトを構成するProject
インスタンスに対してプロジェクトのビルドファイルを実行します。
あなたのスクリプトが使用するようないくつかのプロパティやメソッドは、組織されたProject
オブジェクトを通して委譲されます。
この意味は、あなたのスクリプトの中でダイレクトにProject
インターフェイスのいくつかのメソッドやプロパティをあなたは使用できるという事です。
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 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.
あなたはProject
プロパティを使用してProject
インスタンスにアクセスできます。これによっていくつかのケースで冴えたスクリプトを作ることができます。
例えば、あなたはプロジェクトの名前を参照するのにname
を使用するのではなく、project.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:
プロジェクトはプロパティを探す5つの「プロパティスコープ」を持っています。あなたはあなたのビルドファイルの中で名前で、もしくはプロジェクトのproperty(String)
メソッドの呼び出しでそれらのプロパティにアクセスできます。
そのスコープとは:
Project
object itself. This scope includes any property getters and setters declared by the
Project
implementation class. For example, getRootProject()
is accessible as the
rootProject
property. The properties of this scope are readable or writable depending on the presence
of the corresponding getter or setter method.
Project
オブジェクト自身。このスコープはProject
をimplemantしたクラスが宣言したいくつかのプロパティのgetter、setterメソッドを含みます。
例えばgetRootProject()
はrootProject
プロパティにアクセス可能です。
このスコープのプロパティは一致したgetter、setterメソッドの存在に依存したままで読み書き可能です。
Convention
object. The properties of this scope may be readable or writable, depending on the convention objects.
conventionプロパティはプロジェクトに付属の各Plugin
によってプロジェクトに追加しました。Plugin
はConvention
オブジェクトを通じてプロジェクトにプロパティやメソッドを追加できます。
このスコープのプロパティは参加しているオブジェクトに依存していて、おそらく読み書き可能です。
compile
is accessible as the compile
property.
プロジェクトのタスク。タスクはそのプロパティの名前を使ってアクセスできます。このスコープのプロパティは読み取り専用です。
例えば、タスクが呼び出したcompile
はcompile
プロパティでアクセスできます。
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.
プロパティを読み込んだ際、プロジェクトは順に上のスコープを探し、発見したプロパティの最初のスコープからの値を返します。見つからない場合は例外がスローされます。
詳しい詳細はproperty(String)
をご覧ください。
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.
プロパティ書き込み時は、プロジェクトは順に上のスコープを探し、プロパティを発見する最初のスコープの中でプロパティをセットします。
もし見つからなければ、例外がスローされます。
詳しい詳細はsetProperty(String, Object)
をご覧ください。
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. 全てのエクストラプロパティは"ext"ネームスペースを通して定義されなければなりません。一度エクストラプロパティが定義された場合、それらは専有オブジェクト(下記のプロジェクト、タスク、サブプロジェクト各々)のケー ス上で可能にし、読み込みや編集ができます。 それは名前空間経由で実行される際に必要な初めの宣言にだけです。
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"を通じてもしくは専有オブジェクトを追加し、エクストラプロパティの読み込みは行われました。
ext.isSnapshot = version.endsWith("-SNAPSHOT") if (isSnapshot) { // do snapshot stuff }
A project has 5 method 'scopes', which it searches for methods: プロジェクトはメソッドを探す5つの「メソッドスコープ」を持っています。
Project
object itself.Project
オブジェクト自身。Action
as a parameter.Convention
object.
conventionメソッドがプロジェクトに適応したプラグインによってプロジェクトに追加しました。
プラグインはプロジェクトのConvention
オブジェクトを通してプロジェクトにプロパティやメソッドを追加できます。Action
parameter. The method calls the 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)
.
プロジェクトのタスク。メソッドはメソッド名のタスクや単一のクロージャーないしはAction
パラメーターから取得した名前を使用してそれぞれのタスクに追加されました。
メソッドの呼び出しは提供されたクロージャに付帯の構成されたタスクのTask.configure(groovy.lang.Closure)
メソッドを呼びます。
例えば、もしプロジェクトがcompile
と呼ばれるタスクを持っていて、その時メソッドは後述のような記述が追加されています。void compile(ClosureconfigureClosure)
修飾子とタイプ | フィールドと説明 |
---|---|
static String |
DEFAULT_BUILD_DIR_NAME
The default build directory name.
|
static String |
DEFAULT_BUILD_FILE
The default project build file name.
|
static String |
DEFAULT_STATUS |
static String |
DEFAULT_VERSION |
static String |
GRADLE_PROPERTIES |
static String |
PATH_SEPARATOR
The hierarchy separator for project and task path names.
|
static String |
SYSTEM_PROP_PREFIX |
修飾子とタイプ | メソッドと説明 |
---|---|
String |
absoluteProjectPath(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(Closure closure)
Adds a closure to be called immediately after this project has been evaluated.
|
void |
allprojects(Action<? super Project> action)
Configures this project and each of its sub-projects.
|
void |
allprojects(Closure configureClosure)
Configures this project and each of its sub-projects.
|
AntBuilder |
ant(Closure configureClosure)
Executes the given closure against the
AntBuilder for this project. |
void |
apply(Closure closure)
Configures this project using plugins or scripts.
|
void |
apply(Map<String,?> options)
Configures this project using plugins or scripts.
|
void |
artifacts(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(Closure closure)
Adds a closure to be called immediately before this project is evaluated.
|
void |
buildscript(Closure configureClosure)
Configures the build script classpath for this project.
|
void |
configurations(Closure configureClosure)
Configures the dependency configurations for this project.
|
Iterable<?> |
configure(Iterable<?> objects,
Closure configureClosure)
Configures a collection of objects via a closure.
|
<T> Iterable<T> |
configure(Iterable<T> objects,
Action<? super T> configureAction)
Configures a collection of objects via an action.
|
Object |
configure(Object object,
Closure configureClosure)
Configures an object via a closure, with the closure's delegate set to the supplied object.
|
<T> NamedDomainObjectContainer<T> |
container(Class<T> type)
Creates a container for managing named objects of the specified type.
|
<T> NamedDomainObjectContainer<T> |
container(Class<T> type,
Closure factoryClosure)
Creates a container for managing named objects of the specified type.
|
<T> NamedDomainObjectContainer<T> |
container(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.
|
CopySpec |
copySpec(Closure closure)
Creates a
CopySpec which can later be used to copy files or create an archive. |
AntBuilder |
createAntBuilder()
Creates an additional
AntBuilder for this project. |
void |
defaultTasks(String... defaultTasks)
Sets the names of the default tasks of this project.
|
boolean |
delete(Object... paths)
Deletes files and directories.
|
void |
dependencies(Closure configureClosure)
Configures the dependencies for this project.
|
int |
depthCompare(Project otherProject)
Compares the nesting level of this project with another project of the multi-project hierarchy.
|
Project |
evaluationDependsOn(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(Action<? super ExecSpec> action)
Executes an external command.
|
ExecResult |
exec(Closure closure)
Executes an external command.
|
File |
file(Object path)
Resolves a file path relative to the project directory of this project.
|
File |
file(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(Object... paths)
Returns a
ConfigurableFileCollection containing the given files. |
ConfigurableFileCollection |
files(Object paths,
Closure configureClosure)
Creates a new
ConfigurableFileCollection using the given paths. |
ConfigurableFileTree |
fileTree(Map<String,?> args)
Creates a new
ConfigurableFileTree using the provided map of arguments. |
ConfigurableFileTree |
fileTree(Object baseDir)
Creates a new
ConfigurableFileTree using the given base directory. |
ConfigurableFileTree |
fileTree(Object baseDir,
Closure configureClosure)
Creates a new
ConfigurableFileTree using the given base directory. |
Project |
findProject(String path)
Locates a project by path.
|
Set<Project> |
getAllprojects()
Returns the set containing this project and its subprojects.
|
Map<Project,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.
|
File |
getBuildDir()
Returns the build directory of this project.
|
File |
getBuildFile()
Returns the build file Gradle will evaluate against this project object.
|
ScriptHandler |
getBuildscript()
Returns the build script handler for this project.
|
Map<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()
Returns the
Convention for this project. |
List<String> |
getDefaultTasks()
Returns the names of the default tasks of this project.
|
DependencyHandler |
getDependencies()
Returns the dependency handler of this project.
|
int |
getDepth()
Returns the nesting level of a project in a multi-project hierarchy.
|
String |
getDescription()
Returns the description of this project.
|
ExtensionContainer |
getExtensions()
Allows adding DSL extensions to the project.
|
Gradle |
getGradle()
Returns the
Gradle invocation which this project belongs to. |
Object |
getGroup()
Returns the group of this project.
|
Logger |
getLogger()
Returns the logger for this project.
|
LoggingManager |
getLogging()
Returns the
LoggingManager which can be used to control the logging level and
standard output/error capture for this project's build script. |
String |
getName()
Returns the name of this project.
|
Project |
getParent()
Returns the parent project of this project, if any.
|
String |
getPath()
Returns the path of this project.
|
PluginContainer |
getPlugins()
Returns the plugins container for this project.
|
Project |
getProject()
Returns this project.
|
File |
getProjectDir()
The directory containing the project build file.
|
Map<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.
|
ResourceHandler |
getResources()
Provides access to resource-specific utility methods, for example factory methods that create various resources.
|
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.
|
Object |
getStatus()
Returns the status of this project.
|
Set<Project> |
getSubprojects()
Returns the set containing the subprojects of this project.
|
TaskContainer |
getTasks()
Returns the tasks of this project.
|
Set<Task> |
getTasksByName(String name,
boolean recursive)
Returns the set of tasks with the given name contained in this project, and optionally its subprojects.
|
Object |
getVersion()
Returns the version of this project.
|
boolean |
hasProperty(String propertyName)
Determines if this project has the given property.
|
ExecResult |
javaexec(Action<? super JavaExecSpec> action)
Executes an external Java process.
|
ExecResult |
javaexec(Closure closure)
Executes a Java main class.
|
File |
mkdir(Object path)
Creates a directory and returns a file pointing to it.
|
Project |
project(String path)
Locates a project by path.
|
Project |
project(String path,
Closure configureClosure)
Locates a project by path and configures it using the given closure.
|
Object |
property(String propertyName)
Returns the value of the given property.
|
String |
relativePath(Object path)
Returns the relative path from the project directory to the given path.
|
String |
relativeProjectPath(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(Object path)
Sets the build directory of this project.
|
void |
setDefaultTasks(List<String> defaultTasks)
Sets the names of the default tasks of this project.
|
void |
setDescription(String description)
Sets a description for this project.
|
void |
setGroup(Object group)
Sets the group of this project.
|
void |
setProperty(String name,
Object value)
Sets a property of this project.
|
void |
setStatus(Object status)
Sets the status of this project.
|
void |
setVersion(Object version)
Sets the version of this project.
|
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. |
void |
subprojects(Closure configureClosure)
Configures the sub-projects of this project.
|
FileTree |
tarTree(Object tarPath)
Creates a new
FileTree which contains the contents of the given TAR file. |
Task |
task(Map<String,?> args,
String name)
Creates a
Task with the given name and adds it to this project. |
Task |
task(Map<String,?> args,
String name,
Closure configureClosure)
Creates a
Task with the given name and adds it to this project. |
Task |
task(String name)
Creates a
Task with the given name and adds it to this project. |
Task |
task(String name,
Closure configureClosure)
Creates a
Task with the given name and adds it to this project. |
URI |
uri(Object path)
Resolves a file path to a URI, relative to the project directory of this project.
|
FileTree |
zipTree(Object zipPath)
Creates a new
FileTree which contains the contents of the given ZIP file. |
compareTo
static final String DEFAULT_BUILD_FILE
static final String PATH_SEPARATOR
static final String DEFAULT_BUILD_DIR_NAME
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. このプロジェクトが所属するルートプロジェクトを階層に沿って返します。シングルプロジェクトのビルドの場合は、このメソッドはそのプロジェクト自身を返します。
File getRootDir()
Returns the root directory of this project. The root directory is the project directory of the root project. このプロジェクトのルートディレクトリを返します。ルートディレクトリはルートプロジェクトのプロジェクトディレクトリです。
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
このプロジェクトのビルドディレクトリを返します。ビルドディレクトリは全ての生成物の生成先ディレクトリです。
ビルドディレクトリのデフォルト値はprojectDir/build
です。
void setBuildDir(Object path)
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.
このプロジェクトのビルドディレクトリにセットします。ビルドディレクトリは全ての生成物の生成先ディレクトリです。
パス値はfile(Object)
記述で評価されます。これは、あなたがビルドディレクトリを明記したファイルオブジェクトや、絶対パスや相対パスなどいろいろな方法で使うことができる事を意味します。
path
- The build directory. This is evaluated as per file(Object)
File getBuildFile()
Returns the build file Gradle will evaluate against this project object. The default is "build.gradle"
. If an embedded script is provided the build file will be null.
Gradleがプロジェクトオブジェクトに対して評価するビルドファイルを返します。
もし埋め込むスクリプトに空っぽのビルドファイルを提供された時、デフォルトは"build.gradle"
です。
Project getParent()
Returns the parent project of this project, if any. もし存在するなら、このプロジェクトの親プロジェクトを返します。
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.
このプロジェクトの名前を返します。プロジェクトの階層の範囲内でプロジェクトの名前はユニークである必要はありません。
あなたはプロジェクトのユニークな識別子のためにgetPath()
メソッドを使うべきです。
String getDescription()
Returns the description of this project. このプロジェクトの記述を返します。
void setDescription(String description)
Sets a description for this project.このプロジェクトに記述をセットします。
description
- The description of the project. Might be null.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 a separators.
このプロジェクトのグループを返します。GradleはグループのtoString()
の値をいつも使います。
グループはパスをドットで区切るのが標準です。
void setGroup(Object group)
Sets the group of this project.このプロジェクトのグループをセットします。
group
- The group of this project. Must not be null.Object getVersion()
Returns the version of this project. Gradle always uses the toString()
value of the version. The
version defaults to "unspecified".
このプロジェクトのバージョンを返します。GradleはバージョンのtoString()
の値をいつも使います。
バージョンのデフォルトは"unspecified"です。
void setVersion(Object version)
Sets the version of this project. このプロジェクトのバージョンをセットします。
version
- The version of this project. Must not be null.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.
void setStatus(Object status)
status
- The status. Must not be null.Map<String,Project> getChildProjects()
Returns the direct children of this project.
void setProperty(String name, 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.
rootDir
project property.Convention
object. For example, the srcRootName
java plugin
property.MissingPropertyException
is thrown.name
- The name of the propertyvalue
- The value of the propertyMissingPropertyException
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 using
name
. 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.
Set<Project> getAllprojects()
Returns the set containing this project and its subprojects.
Set<Project> getSubprojects()
Returns the set containing the subprojects of this project.
Task task(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 createdInvalidUserDataException
- If a task with the given name already exists in this project.Task task(Map<String,?> args, 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 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.
args
- The task creation options.name
- The name of the task to be createdInvalidUserDataException
- If a task with the given name already exists in this project.Task task(Map<String,?> args, 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. 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(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.
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.String getPath()
Returns the path of this project. The path is the fully qualified name of the project.
List<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(List<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(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.Project evaluationDependsOn(String path) throws UnknownProjectException
Declares that this project has an evaluation 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 evaluationDependsOnChildren()
Declares that this project has an evaluation dependency on each of its child projects.
Project findProject(String path)
Locates a project by path. If the path is relative, it is interpreted relative to this project.
path
- The path.Project project(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(String path, Closure configureClosure)
Locates a project by path and configures it using the given closure. If the path is relative, it is interpreted relative to this project. The target project is passed to the closure as the closure's delegate.
path
- The path.configureClosure
- The closure to use to configure the project.UnknownProjectException
- If no project with the given path exists.Map<Project,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.Set<Task> getTasksByName(String name, boolean recursive)
Returns the set of tasks with the given name contained in this project, and optionally its subprojects.
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.File getProjectDir()
The directory containing the project build file.
File file(Object path)
Resolves a file path relative to the project directory of this project. This method converts the supplied path based on its type:
CharSequence
, including String
or GString
. Interpreted relative to the project directory. A string
that starts with file:
is treated as a file URL.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.URI
or URL
. The URL's path is interpreted as the file path. Currently, only
file:
URLs are supported.
Closure
. The closure's return value is resolved recursively.Callable
. The callable's return value is resolved recursively.path
- The object to resolve as a File.File file(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.URI uri(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.
path
- The object to resolve as a URI.String relativePath(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.
path
- The path to convert to a relative path.ConfigurableFileCollection files(Object... paths)
Returns a ConfigurableFileCollection
containing the given files. You can pass any of the following
types to this method:
CharSequence
, including String
or GString
. Interpreted relative to the project directory, as per file(Object)
. A string
that starts with file:
is treated as a file URL.File
. Interpreted relative to the project directory, as per file(Object)
.URI
or URL
. The URL's path is interpreted as a file path. Currently, only
file:
URLs are supported.
Collection
, Iterable
, 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.Task
. Converted to the task's output files.TaskOutputs
. Converted to the output files the related task.toString()
value is treated the same way as a String, as per file(Object)
.
This has been deprecated and will be removed in the next version of Gradle.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(Object paths, Closure configureClosure)
Creates a new ConfigurableFileCollection
using the given paths. The paths are evaluated as per 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 per files(Object...)
.configureClosure
- The closure to use to configure the file collection.ConfigurableFileTree fileTree(Object baseDir)
Creates a new ConfigurableFileTree
using the given base directory. The given baseDir path is evaluated
as per 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.
def myTree = fileTree("src") myTree.include "**/*.java" myTree.builtBy "someTask" task copy(type: Copy) { from myTree }
baseDir
- The base directory of the file tree. Evaluated as per file(Object)
.ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure)
Creates a new ConfigurableFileTree
using the given base directory. The given baseDir path is evaluated
as per file(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.
baseDir
- The base directory of the file tree. Evaluated as per file(Object)
.configureClosure
- Closure to configure the ConfigurableFileTree
object.ConfigurableFileTree fileTree(Map<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.
args
- map of property assignments to ConfigurableFileTree
objectFileTree zipTree(Object zipPath)
Creates a new FileTree
which contains the contents of the given ZIP file. The given zipPath path is
evaluated as per file(Object)
. You can combine this method with the copy(groovy.lang.Closure)
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.
zipPath
- The ZIP file. Evaluated as per file(Object)
.FileTree tarTree(Object tarPath)
FileTree
which contains the contents of the given TAR file. The given tarPath path can be:
Resource
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(groovy.lang.Closure)
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' }
tarPath
- The TAR file or an instance of Resource
.File mkdir(Object path)
path
- The path for the directory to be created. Evaluated as per file(Object)
.InvalidUserDataException
- If the path points to an existing file.boolean delete(Object... paths)
paths
- Any type of object accepted by files(Object...)
ExecResult javaexec(Closure closure)
JavaExecSpec
.closure
- The closure for configuring the execution.ExecResult javaexec(Action<? super JavaExecSpec> action)
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.
action
- The action for configuring the execution.ExecResult exec(Closure closure)
ExecSpec
.closure
- The closure for configuring the execution.ExecResult exec(Action<? super ExecSpec> action)
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.
action
- The action for configuring the execution.String absoluteProjectPath(String path)
Converts a name to an absolute project path, resolving names relative to this project.
path
- The path to convert.String relativeProjectPath(String path)
Converts a name to a project path 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. 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 builder
task printChecksum { doLast { ant { checksum(property: 'checksumOut') { fileset(dir: '.') { include name: 'agile1.txt' } } } logger.lifecycle("The checksum is $ant.checksumOut") } }
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(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. See example in javadoc for getAnt()
configureClosure
- The closure to execute against the AntBuilder
.AntBuilder
. Never returns null.ConfigurationContainer getConfigurations()
ConfigurationContainer
void configurations(Closure configureClosure)
Configures the dependency configurations for this project.
This method executes the given closure against the ConfigurationContainer
for this project. The ConfigurationContainer
is passed to the closure as the closure's delegate.
ConfigurationContainer
configureClosure
- the closure to use to configure the dependency configurations.ArtifactHandler getArtifacts()
ArtifactHandler
void artifacts(Closure configureClosure)
Configures the published artifacts for this project.
This method executes the given closure against the ArtifactHandler
for this project. The ArtifactHandler
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 }
configureClosure
- the closure to use to configure the published artifacts.Convention getConvention()
Returns 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)
Configures the sub-projects of this project
This method executes the given Action
against the sub-projects of this project.
action
- The action to execute.void subprojects(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.
configureClosure
- The closure to execute.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.
action
- The action to execute.void allprojects(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.
configureClosure
- The closure to execute.void beforeEvaluate(Action<? super Project> action)
action
- the action to execute.void afterEvaluate(Action<? super Project> action)
action
- the action to execute.void beforeEvaluate(Closure closure)
Adds a closure to be called immediately before this project is evaluated. The project is passed to the closure as a parameter.
closure
- The closure to call.void afterEvaluate(Closure closure)
Adds a closure to be called immediately after this project has been evaluated. The project is passed to the closure as a parameter. Such a listener gets notified when the build file belonging to this project has been executed. A parent project may for example add such a listener to its child project. Such a listener can further 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(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.Map<String,?> getProperties()
Returns the properties of this project. See here for details of the properties which are available for a project.
Object property(String propertyName) throws MissingPropertyException
Returns the value of the given property. This method locates a property as follows:
MissingPropertyException
is thrown.propertyName
- The name of the property.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.
Gradle getGradle()
Returns the Gradle
invocation which this project belongs to.
LoggingManager getLogging()
LoggingManager
which can be used to control the logging level and
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.Object configure(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() }
object
- The object to configureconfigureClosure
- The closure with configure statementsIterable<?> configure(Iterable<?> objects, Closure configureClosure)
configure(Object,
groovy.lang.Closure)
for each of the given objects.objects
- The objects to configureconfigureClosure
- The closure with configure statements<T> Iterable<T> configure(Iterable<T> objects, Action<? super T> configureAction)
objects
- The objects to configureconfigureAction
- The action to apply to each objectRepositoryHandler getRepositories()
void repositories(Closure configureClosure)
Configures the repositories for this project.
This method executes the given closure against the 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.DependencyHandler getDependencies()
DependencyHandler
getConfigurations()
void dependencies(Closure configureClosure)
Configures the dependencies for this project.
This method executes the given closure against the DependencyHandler
for this project. The DependencyHandler
is passed to the closure as the closure's delegate.
DependencyHandler
configureClosure
- the closure to use to configure the dependencies.PluginContainer getPlugins()
getPlugins
インタフェース内 PluginAware
ScriptHandler getBuildscript()
void buildscript(Closure configureClosure)
Configures the build script classpath for this project.
The given closure is executed against this project's ScriptHandler
. The ScriptHandler
is
passed to the closure as the closure's delegate.
configureClosure
- the closure to use to configure the build script classpath.WorkResult copy(Closure closure)
CopySpec
, which is then used to
copy the files. Example:
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 CopySpecWorkResult
that can be used to check if the copy did any work.CopySpec copySpec(Closure closure)
CopySpec
which can later be used to copy files or create an archive. The given closure is used
to configure the CopySpec
before it is returned by this method.
def baseSpec = copySpec { from "source" include "**/*.java" } task copy(type: Copy) { into "target" with baseSpec }
closure
- Closure to configure the CopySpecvoid apply(Closure closure)
Configures this project using plugins or scripts. The given closure is used to configure an ObjectConfigurationAction
which is then used to configure this project.
apply
インタフェース内 PluginAware
closure
- The closure to configure the ObjectConfigurationAction
.void apply(Map<String,?> options)
Configures this project using plugins or scripts. The following options are available:
from
: A script to apply to the project. Accepts any path supported by uri(Object)
.plugin
: The id or implementation class of the plugin to apply to the project.to
: The target delegate object or objects. Use this to configure objects other than the
project.For more detail, see ObjectConfigurationAction
.
apply
インタフェース内 PluginAware
options
- The options to use to configure the ObjectConfigurationAction
.ProjectState getState()
<T> NamedDomainObjectContainer<T> container(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.
T
- The type of objects for the container to contain.type
- The type of objects for the container to contain.<T> NamedDomainObjectContainer<T> container(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.
T
- The type of objects for the container to contain.type
- The type of objects for the container to contain.factory
- The factory to use to create object instances.<T> NamedDomainObjectContainer<T> container(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.
T
- The type of objects for the container to contain.type
- The type of objects for the container to contain.factoryClosure
- The closure to use to create object instances.ExtensionContainer getExtensions()
getExtensions
インタフェース内 ExtensionAware
ResourceHandler getResources()
@Incubating SoftwareComponentContainer getComponents()