Declare task as project.task('copyAppForDocker') or task copyAppForDocker <<

Here is the code of my working task:

def thisProject = project

task copyAppForDocker << {
  project.rootProject.allprojects { p ->
    p.plugins.withType(EarPlugin) {
      def appRoot = "${thisProject.projectDir}/applications"
      def dir = new File(appRoot)
      if (!dir.exists()) dir.mkdirs()
      def src = new File("${p.ear.archivePath}")
      def dst = new File("${appRoot}/${p.ear.archiveName}")
      dst << src.bytes

project.tasks.deployDocker.dependsOn project.tasks.copyAppForDocker

Originally I declared my task as project.task(‘copyAppForDocker’)

When I did this the task was called every time I did a build or clean. As soon as I change the task declaration to “task copyAppForDocker <<” it stopped doing it and only executed when I called it.