-
Notifications
You must be signed in to change notification settings - Fork 43
/
plugin.gradle
74 lines (67 loc) · 2.11 KB
/
plugin.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* 看效果在这 app > build.gradle > apply from : '../plugin.gradle'
*/
// 不嵌套
//interface YechaoaPluginExtension {
// Property<String> getTitle()
// Property<Integer> getChapter()
//}
//
//class YechaoaPlugin implements Plugin<Project> {
//
// @Override
// void apply(Project project) {
// println("这是插件:${this.class.name}")
// def extension = project.extensions.create("yechaoa", YechaoaPluginExtension)
// extension.title.convention("默认配置title")
// extension.chapter.convention(0)
//
//
// project.task("YechaoaPluginTask") { task ->
// task.doLast {
// println("这是插件${this.class.name},它创建了一个Task:${task.name}")
// println("title = ${extension.title.get()}")
// println("chapter = ${extension.chapter.get()}")
//
// println("desc = ${extension.getSubExtension().get().getDesc().get()}")
// }
// }
// }
//}
// 嵌套
class YechaoaPluginExtension {
String title
int chapter
SubExtension subExtension
YechaoaPluginExtension(Project project) {
subExtension = project.extensions.create('sub', SubExtension.class)
}
}
class SubExtension {
String author
}
class YechaoaPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
println("这是插件:${this.class.name}")
def extension = project.extensions.create("yechaoa", YechaoaPluginExtension)
// 设置默认值 可以定义set()方法 然后在这里set
project.task("YechaoaPluginTask") { task ->
task.doLast {
println("这是插件${this.class.name},它创建了一个Task:${task.name}")
println("title = ${extension.title}")
println("chapter = ${extension.chapter}")
println("author = ${extension.subExtension.author}")
}
}
}
}
apply plugin: YechaoaPlugin
//apply(plugin: YechaoaPlugin)
yechaoa {
title = "【Gradle-8】Gradle插件开发指南"
chapter = 8
sub {
author = "yechaoa"
}
}