Gradle/Groovy Custom plugin

I am new to Plugin development and Gradle.How do I include depends on option in Custom Plugin.
@TaskAction
def localBuild(){
println" Local build started…"
dependsOn{
“clean”
“classes”
}
doLast{
copy {
println “configurations.runtime”+configurations.runtime

		from configurations.runtime
		into project.projectDir.toString() + "/src/main/webapp/WEB-INF/lib"
		println"into"+project.projectDir.toString()
		}
	}
}

Hi,

I suggest you start by reading https://docs.gradle.org/current/userguide/custom_plugins.html, then maybe get copy of Idiomatic Gradle Vol 1. You can also clone this plugin workshop repo and then work through the exercises.

Now as to some detail of what you asked above:

  • @TaskAction defines the primary action to be invoked by the task. You cannot put any configuration items in there.
  • doLast is a way of adding more actions, put usually that code itself should be inside the primary task action. Idiomatically doLast and doFirst are reserved for build script authors to customise the behaviour of an existing task.
class MyTask extends DefaultTask {
    @TaskAction
    void localBuild() {
        println 'Local build started...'
        project.copy {
            // ... copy code goes here
        }
    }
}

class MyPlugin implements Plugin<Project> {
    void apply(Project project) {
        Task myTask = project.tasks.create( 'myTask', MyTask)
        myTask.dependsOn 'clean', 'classes'
    }
}

HTH

Thank you very much. That helped a lot. I appreciate it.