Gradle Task with global scope

I want to write a set of global tasks which should be available in every project in my multip-project setup. The tasks are not project-related and thus should be executed only once, also if I execute the task in the root folder. How can I achieve that?

In the root project I put this build.gradle:

allprojects {
task myTask() {
 doLast{
  println("hello world")
 }
}
}

If I run the task “myTask” in root folder, the task will be executed in root and all subprojects. I want to execute the task only once.

A simple solution is to remove the ‘allprojects {}’. You can then execute the task from a subproject directory with ‘gradle :myTask’.

Thanks, sounds like a pragmatic solution.