Frist VariantProcessor
Introducing Booster
After preparing the project, add the Booster dependency in the build.gradle file of the Java Library project or the buildSrc directory of the Android project:
buildscript {
ext {
agp_version = "3.5.0"
kotlin_version = "1.5.31"
booster_version = "4.16.3"
}
repositories {
mavenCentral()
google()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
repositories {
mavenCentral()
google()
}
sourceSets {
main {
java {
srcDirs += []
}
kotlin {
srcDirs += ['src/main/kotlin', 'src/main/java']
}
}
test {
java {
srcDirs += []
}
kotlin {
srcDirs += ['src/main/kotlin', 'src/main/java']
}
}
}
compileKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}
compileTestKotlin {
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8
}
dependencies {
api gradleApi()
/* 👇👇👇👇 Reference these three modules 👇👇👇👇 */
kapt "com.google.auto.service:auto-service:1.0"
api 'com.android.tools.build:gradle:$agp_version'
api "com.didiglobal.booster:booster-api:$booster_version"
}
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
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
Custom VariantProcessor
package io.johnsonlee.booster.demo
import com.android.build.gradle.api.BaseVariant
import com.didiglobal.booster.gradle.project
import com.didiglobal.booster.task.spi.VariantProcessor
import com.google.auto.service.AutoService
@AutoService(VariantProcessor::class)
class SimpleVariantProcessor(val project: Project) : VariantProcessor {
init {
println("${project.name}")
}
override fun process(variant: BaseVariant) {
println("${variant.project.name}: ${variant.name}")
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
TIP
The Project parameter in the VariantProcessor constructor is optional.
Verifying FirstVariantProcessor
In the Android project, execute the assemble task:
$ ./gradlew assembleDebug
1
Observe the console standard output to see if it contains content like:
app: debug
app: release
1
2
2
