Custom gradle plugin task is only executed once in subprojects

Hello everyone,

I have written custom a gradle plugin in Java, which I want to use in a multiproject gradle setup. I applied the plugin in the subprojects section of my build.gradle. The task which comes with the plugin is only executed once and I don’t understand why.

The structure of the project looks like this:

Root project
     |- settings.gradle
     |- build.gradle
     |- project1
     |     |- build.gradle
     |- project2
     |     |- build.gradle
     |- project3
     |     |- build.gradle

The root build.gradle looks like this

buildscript {
repositories {
    maven { url "" }
    maven { url "" }

        url = ""
    dependencies {
       classpath "de.mystuff:myCustomPlugin:1.0.0"
subprojects {
   apply plugin: "myCustomPlugin"

The plugin “myCustomPlugin” provides 2 Tasks called myTask and myDocTask. Since the plugin is applied in die subprojects part of the build.gradle, I assumed that when I call:

./gradlew myTask

the task would be executed for project1, project2, project3.

In reality the task only executes in project1 and not in project2 or project3. If I call

./gradlew -p "project2" myTask

the task is executed in project 2 just fine. Any hints on why the task is not executed for every subproject?

When I call

 ./gradlew tasks --all

The result shows the task is registered for every subproject.

The Plugin is written in java. The code of the task looks like this:

public class MyGeneratorTask extends DefaultTask {

public void genMyCode() throws Exception {
        MyGeneratorExtension extension = getProject().getExtensions().getByType(MyGeneratorExtension.class);

And the plugin definition itself:

public class MyPlugin implements Plugin<Project> {
    static final String GEN_TASK_CONFIG = "myConfig";
    static final String GEN_TASK_NAME = "myTask";
    static final String DOC_TASK_NAME ="myDocTask";

    public void apply(Project target) {
        target.getExtensions().add(GEN_TASK_CONFIG, MyGeneratorExtension.class);
        target.getTasks().create(GEN_TASK_NAME, MyGeneratorTask.class);
        target.getTasks().create(DOC_TASK_NAME , MyDocTask.class);

And the code of the extension:

import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = false)
public class MyGeneratorExtension {

   private String path;
   private String gendir;


Some additional information:

  • The tasks are not marked as SKIPPED. They never show up in the task history. When I run the task the build says:
    1 actionable task: 1 executed

Thanks for your help!