Skip to content

Instantly share code, notes, and snippets.

@PaoloMilano
Created May 2, 2020 12:09
Show Gist options
  • Select an option

  • Save PaoloMilano/4ebda4ab66b3f3cf193dfff412ee0fb7 to your computer and use it in GitHub Desktop.

Select an option

Save PaoloMilano/4ebda4ab66b3f3cf193dfff412ee0fb7 to your computer and use it in GitHub Desktop.
class MyFirstPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.android().variants().all { variant ->
// Make a task for each combination of build type and product flavor
val myTask = "myFirstTask${variant.name.capitalize()}"
// Register a simple task as a lambda. We can later move this to its own
// class to make our code cleaner and also add some niceties.
project.tasks.create(myTask){task ->
// Group all our plugin's tasks together
task.group = "MyPluginTasks"
task.doLast {
File("${project.projectDir.path}/myFirstGeneratedFile.txt").apply {
writeText("Hello Gradle!\nPrinted at: ${SimpleDateFormat("HH:mm:ss").format(Date())}")
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment