什么时候使用gradle.properties和settings.gradle? [英] When to use gradle.properties vs. settings.gradle?
问题描述
gradle构建具有三个文件
A gradle build has three files
-
build.gradle
构建配置脚本 -
gradle.properties
-
settings.gradle
build.gradle
that defines the build configuration scriptsgradle.properties
settings.gradle
问题
-
settings.gradle
&gradle.properties
? - 何时应将设置放入
settings.gradle
与
gradle.properties
?
- What are differences between
settings.gradle
&gradle.properties
? - When should a settings be put in
settings.gradle
vs.gradle.properties
?
推荐答案
settings.gradle
settings.gradle
文件是Groovy脚本,就像 build.gradle
文件一样。每个版本中只会执行一个 settings.gradle
脚本(相比之下,多个版本中的多个 build.gradle
脚本项目构建)。 settings.gradle
脚本将在任何 build.gradle
脚本之前甚至在 Project
实例已创建。因此,将根据 进行评估设置
对象。使用此设置
对象,您可以将子项目添加到构建中,从命令行修改参数( StartParameter
),然后访问 Gradle
对象来注册生命周期处理程序。因此,如果您的设置与构建相关,而不一定与项目相关,或者需要之前包含子项目,则使用 settings.gradle
。
settings.gradle
The settings.gradle
file is a Groovy script, just like the build.gradle
file. Only one settings.gradle
script will be executed in each build (in comparison to multiple build.gradle
scripts in multi-project builds). The settings.gradle
script will be executed before any build.gradle
script and even before the Project
instances are created. Therefore, it is evaluated against a Settings
object. With this Settings
object you can add subprojects to your build, modify the parameters from the command line (StartParameter
), and access the Gradle
object to register lifecycle handlers. As a consequence, use settings.gradle
if your settings are build-related and not necessarily project-related or require logic before possible subprojects are included.
gradle.properties
文件是一个简单的Java 属性
文件仅通过自动包含在 Project $ c的范围内而具有特殊作用$ c>对象(即所谓的项目属性)。这是一个简单的键值存储,仅允许使用字符串值(因此,您需要自己分割列表或数组)。您可以将
gradle.properties
文件放入以下位置:
The gradle.properties
file is a simple Java Properties
file that only gains a special role by being automatically included into the scope of the Project
object (as so-called 'project properties'). It's a simple key-value store that only allows string values (so you need to split lists or arrays by yourself). You can put gradle.properties
files to these locations:
- 直接在项目中目录(用于与项目相关的值)
- 位于用户主目录
.gradle
目录(用于与用户或环境相关的值)
- directly in the project directory (for project-related values)
- in the user home
.gradle
directory (for user- or environment-related values)
这篇关于什么时候使用gradle.properties和settings.gradle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!