-
Notifications
You must be signed in to change notification settings - Fork 579
How to Create Customized Transformer
Johnson Lee edited this page Jun 27, 2019
·
2 revisions
Booster provides Binary Transformer, ASM-based Transformer and Javassist-based Transformer, the following sample code shows how to create an instance of transformer for bytecode manipulation.
@AutoService(ClassTransformer::class)
class MyTransformer : ClassTransformer {
override fun transform(context: TransformContext, klass: ClassNode): ClassNode {
// Do whatever you want
return klass
}
}
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>" ...... } }
Please see transformer-with-asm and transformer-with-javassist