This sample demonstrates how to use the LifecycleTasks.registerPreBuild()
API
to register tasks to run before a build begins.
Module | Content |
---|---|
build-logic | Contains the Project plugin that is the core of the recipe. |
app | An Android application that has the plugin applied. |
The build-logic sub-project contains the CustomPlugin
and PreBuildValidationTask
classes.
CustomPlugin
contains the creation of the task provider for the PreBuildValidationTask
. The API call
to register this task per-variant is below:
androidComponents.onVariants { variant ->
variant.lifecycleTasks.registerPreBuild(preBuildTaskProvider)
}
CustomPlugin
also registers the ValidateTask
which verifies that the pre-build task ran.
To run the example, you can just do
./gradlew :app:build
and you should see the file created by the task in app/build/preBuildOutput/gradle_version.txt
.