Tasks get executed when invoking irrelevant tasks

build.gradle

plugins {
        id 'eclipse'
}
  allprojects {
          task publishAll() {
                println "publishAll ..........."
        }
}
  subprojects {
          task publishSub() {
                println "publishSub ..........."
        }
}

output:

$ gradle eclipse
                                                                                        publishAll ...........
publishAll ...........
publishAll ...........
publishSub ...........
publishSub ...........
:eclipseProject
:eclipse

Although I get this fixed by adding doFirst block to the task ( http://forums.gradle.org/gradle/topics/why_is_my_task_being_executed). But I think this still a issue. These tasks should not run without invokel/dependsOn.

Daz explained this behavior in the linked thread. Your task is not being executed, however it is being configured, which is why the ‘println’ statement is evaluated. Code you intend to run only during execution should be placed in a task action like a ‘doFirst’ or ‘doLast’ block.