59 lines
2.4 KiB
Markdown
59 lines
2.4 KiB
Markdown
- `settings file:` `gradle` 的 `entry point`
|
||
- 对于单模块项目 `settings` 文件可选
|
||
- 多模块项目 `settings` 文件用来声明和控制 子项目
|
||
- 具体文件内容
|
||
```kotlin
|
||
rootProject.name = "root-project" // 定义项目名称
|
||
include("app") // 使用include引入subproject, 用来定义项目结构
|
||
include("feature")
|
||
plugins { //
|
||
id("java") version "" // 引入插件,可选;
|
||
}
|
||
```
|
||
- `build.gradle.kts` : 每一个 `gradle` 的构建至少包含一个build脚本文件
|
||
- `plugins` :构建需要的依赖,
|
||
- 插件通过扩展`Gradle`来配置或着设置构建需要的`task`, 还可以用来进行依赖管理,插件还会在build.gradle.kts 中添加新的属性或者方法,来增加配置,下面的application就是`application`插件定义的一个
|
||
- `application`: 源码
|
||
- 依赖管理
|
||
- 依赖管理,用来声明和解析项目所需的外部资源(依赖项)。包括构建项目需要需要的jar、插件、库和源代码。
|
||
- `libs.versions.toml` 版本目录
|
||
- 所包含的部分
|
||
- `versions` 定义插件和库文件的 版本数字
|
||
- `libraries` 定义需要使用的依赖库
|
||
- `bundles`
|
||
- `plugin` 定义需要使用的插件
|
||
- 举例如下
|
||
```toml
|
||
[versions]
|
||
androidGradlePlugin = "7.4.1"
|
||
mockito = "2.16.0"
|
||
|
||
[libraries]
|
||
googleMaterial = { group = "com.google.android.material", name = "material", version = "1.1.0-alpha05" }
|
||
mockitoCore = { module = "org.mockito:mockito-core", version.ref = "mockito" }
|
||
|
||
[plugins]
|
||
androidApplication = { id = "com.android.application", version.ref = "androidGradlePlugin" }
|
||
```
|
||
- libs.versions.toml 文件放在gradle项目中的gradle目录下,gradle 和 IDE都可以自动使用这个版本目录
|
||
- build中引入依赖
|
||
- 在使用了libs.versions.toml之后就可以使用libs.version.toml 中的定义的方式来引入依赖
|
||
- 示例:
|
||
```kotlin
|
||
plugins {
|
||
alias(libs.plugins.androidApplication)
|
||
}
|
||
|
||
dependencies {
|
||
// Dependency on a remote binary to compile and run the code
|
||
implementation(libs.googleMaterial)
|
||
|
||
// Dependency on a remote binary to compile and run the test code
|
||
testImplementation(libs.mockitoCore)
|
||
}
|
||
```
|
||
- Task
|
||
- Plugin
|
||
- 增量构建 + 缓存
|
||
- 增量构建: 如果两次相同的构建之间,没有修改项目中的内容,则不会发生新的构建,而是打印出一个 `UP-TO-DATE`
|
||
- |