Gradle
可以研究下 Project Api
DEBUG
1 | ./gradlew "-Dorg.gradle.daemon=false" "-Dorg.gradle.debug=true" :tasks |
9:37
Gradle Lifecycle
https://docs.gradle.org/current/userguide/build_lifecycle.html
Initialization
Detects the settings file.Evaluates the settings file to determine which projects and included builds participate in the build.Creates a
Project
instance for every project.Configuration
Evaluates the build scripts of every project participating in the build.Creates a task graph for requested tasks.
本质上把build.gradle从上到下跑一遍。
Execution
Schedules and executes each of the selected tasks in the order of their dependencies.
任务
https://www.bilibili.com/video/BV1m54y1L7vK/
https://www.bilibili.com/video/BV1dK411K7Pg
https://www.bilibili.com/video/BV1DE411Z7nt
https://www.bilibili.com/video/BV1dp4y1e7W4
注意Android stuio默认关闭task 按钮
静态任务
1 | println("gradle study") |
./gradlew helloworld
动态任务
“configure” 在生命周期Configuration 阶段就执行。
dolast dofirst只是加入到任务中,只有指定具体执行的任务,才会执行,就像上面的 ./gradlew helloworld,指明helloworld任务。
闭包
1 | task testGrdele{ |
Plugin
Scrpit Plugin
CustomGradlePlugin
./gradlew CustomGradlePlugin
1 | //1.脚本插件 |
./gradlew scriptPlugin
1 | apply from: "config.gradle" |
1 | project.task("scriptPlugin") { |
ankotlin:this is a scriptPlugin
MyAwesomePlugin
1 | class MyAwesomePlugin implements Plugin<Project>{ |
buildscript 可以把java complile的classpath加入到build.gradle中
Use Plungin in build.gradle
1 | buildscript { |
这样就能使用java的方法在build.gradle中。