-
Notifications
You must be signed in to change notification settings - Fork 580
How to Create Customized Task
johnsonlee edited this page Apr 24, 2019
·
1 revision
The following sample code shows how to create an instance of MyTask for each variant.
@AutoService(VariantProcessor::class)
class MyVariantProcessor : VariantProcessor {
override fun process(variant: BaseVariant) {
val tasks = variant.scope.globalScope.project.tasks
tasks.create("my${variant.name.capitalize()}Task", MyTask::class.java) {
it.variant = variant
it.outputs.upToDateWhen { false }
}
}
}
open class MyTask : DefaultTask() {
lateinit var variant: BaseVariant
@TaskAction
fun run() {
// Do whatever you want
}
}
Typically, there are two approaches to apply customized tasks:
-
Applying with buildSrc
Just simply put the classes above into
${rootProject}/buildSrc/src
. -
Applying as standalone module
For this approach, a standalone gradle module have to be created, and then, add this module into buildscript classpath:
buildscript { ...... dependencies { classpath "com.didiglobal.booster:booster-gradle-plugin:$booster_version" classpath "<standalone-group-id>:<standalone-artifact-id>:<standalone-version>" ...... } }