class, generating javadoc, ... Can be manipulated doFirst, doLast Can inherit from another type Can depend on another task dependsOn, finalizedBy DEFINITIONS The Gradle Task
the extension project.extensions.create(“achivetest”,ArchiveTestPluginExtension, project) //create the tasks project.task(name:“achivetest”, type:ArchiveTask){} //link the tasks to the build chain Task task = project.tasks.getByName(project.archivetest.task) task.finalizedBy “achivetest” } } THE CODE The Plugin class
} @TaskAction def exec() { println "Reports copied into ${project.archivetest.into}" } } THE CODE We want a Copy task. Use DefaultTask to implement your own The Task class
def into def task ArchiveTestPluginExtension(Project project) { from = project. reportsDir into = project.projectDir+"/reports/report-${currentTimeMillis()}" task = "test" } } This is a simple POGO
} } apply plugin: 'archivetest' archivetest { from "build/report" into "/tmp/archives" task “connectedAndroidTest” } THE CODE The user’s build.gradle The local repository folder
the extension project.extensions.create(“achivetest”,ArchiveTestPluginExtension, project) //create the tasks project.task(name:“achivetest”, type:ArchiveTask){} //link the tasks to the build chain Task task = project.tasks.getByName(project.archivetest.task) task.finalizedBy “achivetest” } } DEBUG IT The Plugin class
the extension project.extensions.create(“achivetest”,ArchiveTestPluginExtension, project) //create the tasks project.task(name:“achivetest”, type:ArchiveTask){} //link the tasks to the build chain Task task = project.tasks.getByName(project.archivetest.task) task.finalizedBy “achivetest” } } DEBUG IT The Plugin class Executed too early
//link the tasks to the build chain Task task = project.tasks.getByName(project.archivetest.task) task.finalizedBy “achivetest” } } DEBUG IT The Plugin class
//link the tasks to the build chain project.afterEvaluate { Task task = project.tasks.getByName(project.archivetest.task) task.finalizedBy “achivetest” } } } DEBUG IT The Plugin class We add the task after the evaluation
--debug ... test.groovy.fr.eyal.ArchiveTestPluginTest > canAddArchiveTask FAILED MissingPropertyException: Could not find property 'archivetest' on task set ... BUILD FAILED
--debug ... test.groovy.fr.eyal.ArchiveTestPluginTest > canAddArchiveTask FAILED MissingPropertyException: Could not find property 'archivetest' on task set ... BUILD FAILED Our task is not created
project.afterEvaluate { //create the tasks project.task(name:“achivetest”, type:ArchiveTask){} //inject the task Task task = project.tasks.getByName(project.archivetest.task) task.finalizedBy “achivetest” } } } TEST IT The Plugin class Tasks are often created after project. evaluate()
don't see this in the API docs for Project because it is an internal method and is therefore potentially subject to change in future releases. There will be a supported mechanism for doing this kind of thing in the near future. ” “
don't see this in the API docs for Project because it is an internal method and is therefore potentially subject to change in future releases. There will be a supported mechanism for doing this kind of thing in the near future. June 2011 ” “