API文档: | Settings |
---|
Project
声明实例化和配置要参与构建的实例层次结构所需的配置。
Settings
实例和设置文件之间存在一一对应的关系
。在 Gradle 组装项目进行构建之前,它会创建一个
settings.gradle
Settings
实例并针对它执行设置文件。
该对象的目的之一Settings
是允许您声明要包含在构建中的项目。您可以使用该方法将项目添加到构建中Settings.include(java.lang.String[])
。构建中始终包含一个根项目。它是在Settings
创建对象时自动添加的。根项目的名称默认为包含设置文件的目录的名称。根项目的项目目录默认为包含设置文件的目录。
当项目包含在构建中时,ProjectDescriptor
就会创建一个。您可以使用此描述符来更改项目的多个属性的默认值。
财产 | 描述 |
buildCache | 构建缓存配置。 |
caches | 孵化 存储在用户主目录中的缓存配置。 |
extensions | 扩展的容器。 |
gradle |
|
pluginManager | 此插件感知对象的插件管理器。 |
plugins | 已应用于此对象的插件的容器。 |
rootDir | 构建的根目录。根目录是根项目的项目目录。 |
rootProject | 构建的根项目。 |
settings | 返回此设置对象。 |
settingsDir | 构建的设置目录。设置目录是包含设置文件的目录。 |
startParameter | 用于调用此 Gradle 实例的参数集。 |
方法 | 描述 |
apply(closure) | 应用零个或多个插件或脚本。 |
apply(options) | 使用作为地图提供的给定选项来应用插件或脚本。如果插件已被应用,则不执行任何操作。 |
apply(action) | 应用零个或多个插件或脚本。 |
buildCache(action) | 配置构建缓存。 |
caches(cachesConfiguration) | 孵化 Configures the settings for caches stored in the user home directory. |
findProject(projectDir) | Returns the project with the given project directory. |
findProject(path) | Returns the project with the given path. |
include(projectPaths) | Adds the given projects to the build. Each path in the supplied list is treated as the path of a project to add to the build. Note that these path are not file paths, but instead specify the location of the new project in the project hierarchy. As such, the supplied paths must use the ':' character as separator (and NOT '/'). |
include(projectPaths) | Adds the given projects to the build. Each path in the supplied list is treated as the path of a project to add to the build. Note that these path are not file paths, but instead specify the location of the new project in the project hierarchy. As such, the supplied paths must use the ':' character as separator (and NOT '/'). |
includeBuild(rootProject) | Includes a build at the specified path to the composite build. |
includeBuild(rootProject, configuration) | Includes a build at the specified path to the composite build, with the supplied configuration. |
includeFlat(projectNames) | Adds the given projects to the build. Each name in the supplied list is treated as the name of a project to add to the build. |
includeFlat(projectNames) | Adds the given projects to the build. Each name in the supplied list is treated as the name of a project to add to the build. |
project(projectDir) | Returns the project with the given project directory. |
project(path) | Returns the project with the given path. |
BuildCacheConfiguration
buildCache
(read-only)
The build cache configuration.
CacheConfigurations
caches
(read-only)
Note: This property is incubating and may change in a future version of Gradle.
The configuration for caches stored in the user home directory.
ExtensionContainer
extensions
(read-only)
The container of extensions.
PluginManager
pluginManager
(read-only)
The plugin manager for this plugin aware object.
PluginContainer
plugins
(read-only)
The container of plugins that have been applied to this object.
While not deprecated, it is preferred to use the methods of this interface or the PluginAware.getPluginManager()
than use the plugin container.
Use one of the 'apply' methods on this interface or on the PluginAware.getPluginManager()
to apply plugins instead of applying via the plugin container.
Use PluginManager.hasPlugin(java.lang.String)
or similar to query for the application of plugins instead of doing so via the plugin container.
File
rootDir
(read-only)
The root directory of the build. The root directory is the project directory of the root project.
ProjectDescriptor
rootProject
(read-only)
The root project of the build.
Settings
settings
(read-only)
Returns this settings object.
File
settingsDir
(read-only)
The settings directory of the build. The settings directory is the directory containing the settings file.
StartParameter
startParameter
(read-only)
The set of parameters used to invoke this instance of Gradle.
void
apply
(Closure
closure)
Applies zero or more plugins or scripts.
The given closure is used to configure an ObjectConfigurationAction
, which “builds” the plugin application.
This method differs from PluginAware.apply(java.util.Map)
in that it allows methods of the configuration action to be invoked more than once.
Applies a plugin or script, using the given options provided as a map. Does nothing if the plugin has already been applied.
The given map is applied as a series of method calls to a newly created ObjectConfigurationAction
.
That is, each key in the map is expected to be the name of a method ObjectConfigurationAction
and the value to be compatible arguments to that method.
The following options are available:
from
: A script to apply. Accepts any path supported byProject.uri(java.lang.Object)
.plugin
: The id or implementation class of the plugin to apply.to
:目标委托对象或对象。默认是这个插件感知对象。使用它来配置除此对象之外的对象。
void
apply
(行动)Action
<? super ObjectConfigurationAction
>
Action
<? super ObjectConfigurationAction
>应用零个或多个插件或脚本。
给定的闭包用于配置ObjectConfigurationAction
“构建”插件应用程序。
此方法的不同之处PluginAware.apply(java.util.Map)
在于它允许多次调用配置操作的方法。
void
buildCache
(行动)Action
<? super BuildCacheConfiguration
>
Action
<? super BuildCacheConfiguration
>配置构建缓存。
void
caches
(缓存配置)Action
<? super CacheConfigurations
>
Action
<? super CacheConfigurations
>注意:此方法正在孵化中,可能会在 Gradle 的未来版本中发生变化。
配置存储在用户主目录中的缓存设置。
ProjectDescriptor
findProject
(File
项目目录)
返回具有给定项目目录的项目。
ProjectDescriptor
findProject
(String
小路)
返回具有给定路径的项目。
将给定的项目添加到构建中。提供的列表中的每个路径都被视为要添加到构建的项目的路径。请注意,这些路径不是文件路径,而是指定新项目在项目层次结构中的位置。因此,提供的路径必须使用“:”字符作为分隔符(而不是“/”)。
所提供路径的最后一个元素用作项目名称。提供的路径将转换为相对于根项目目录的项目目录。包含项目后,可以通过更改 'projectDir' 属性来更改项目目录(请参阅ProjectDescriptor.setProjectDir(java.io.File)
)
例如,路径添加一个包含路径、名称和项目目录的a:b
项目。它还添加具有路径、名称和项目目录的项目(如果尚不存在)。:a:b
b
$rootDir/a/b
:a
a
$rootDir/a
使用项目路径的一些常见示例是:
// include two projects, 'foo' and 'foo:bar' // directories are inferred by replacing ':' with '/' include(['foo:bar']) // include one project whose project dir does not match the logical project path include(['baz']) project(':baz').projectDir = file('foo/baz') // include many projects whose project dirs do not match the logical project paths file('subprojects').eachDir { dir -> include([dir.name]) project(":${dir.name}").projectDir = dir }
void
include
(String
...
项目路径)
String
...将给定的项目添加到构建中。提供的列表中的每个路径都被视为要添加到构建的项目的路径。请注意,这些路径不是文件路径,而是指定新项目在项目层次结构中的位置。因此,提供的路径必须使用“:”字符作为分隔符(而不是“/”)。
所提供路径的最后一个元素用作项目名称。提供的路径将转换为相对于根项目目录的项目目录。包含项目后,可以通过更改 'projectDir' 属性来更改项目目录(请参阅ProjectDescriptor.setProjectDir(java.io.File)
)
例如,路径添加一个包含路径、名称和项目目录的a:b
项目。它还添加具有路径、名称和项目目录的项目(如果尚不存在)。:a:b
b
$rootDir/a/b
:a
a
$rootDir/a
使用项目路径的一些常见示例是:
// include two projects, 'foo' and 'foo:bar' // directories are inferred by replacing ':' with '/' include 'foo:bar' // include one project whose project dir does not match the logical project path include 'baz' project(':baz').projectDir = file('foo/baz') // include many projects whose project dirs do not match the logical project paths file('subprojects').eachDir { dir -> include dir.name project(":${dir.name}").projectDir = dir }
void
includeBuild
(Object
根项目)
包括复合构建的指定路径处的构建。
void
includeBuild
(Object
根项目,配置)Action
<ConfigurableIncludedBuild
>
Action
<ConfigurableIncludedBuild
>包括复合构建的指定路径处的构建以及提供的配置。
将给定的项目添加到构建中。提供的列表中的每个名称都被视为要添加到构建的项目的名称。
提供的名称将转换为相对于根项目目录的父目录的项目目录。
例如,名称添加一个包含路径、名称和项目目录的
a
项目。:a
a
$rootDir/../a
void
includeFlat
(String
...
项目名称)
String
...将给定的项目添加到构建中。提供的列表中的每个名称都被视为要添加到构建的项目的名称。
提供的名称将转换为相对于根项目目录的父目录的项目目录。
例如,名称添加一个包含路径、名称和项目目录的
a
项目。:a
a
$rootDir/../a
ProjectDescriptor
project
(File
项目目录)
返回具有给定项目目录的项目。
ProjectDescriptor
project
(String
小路)
返回具有给定路径的项目。