Why does this rule not get called?

Continuing the discussion from New model confusion:

Was scratching my head today, but cannot figure out why addTasks never gets called.

@Managed
interface DockerContainer  {
    void setDockerDir(File location)
    File getDockerDir()
}

@Model
void dockerComponents(ModelMap<DockerContainer> components) {
}

@Mutate
void addTasks(ModelMap<Task> tasks, ModelMap<DockerContainer> components) {
   /* ... Never gets called */
}

I don’t use collections in my model, but based on how most of the software component bits seem to work, how about:

@Mutate
void addTasks(ModelMap<Task> tasks, DockerContainer component) {
   /* Gets one component for each call */
}

Hmm, I realize I do have a few methods that take a collection, but they also take a single extension parameter, or, they specify the path of the collection, like this: (Still no @Model collection though)

        @Mutate
        void doStuff(ModelMap<Task> tasks, ModelMap<MySpecInternal> specs, MyExtension extension) {
            /* stuff */
        }

        @Mutate
        void addTasks(@Path("tasks.assemble") Task lifecycle, @Path("binaries") ModelMap<MyBaseBinarySpec> specs) {
            /* stuff */
        }
1 Like

This is working for me in Gradle 2.13, where every product created gets a generate task. What does your model block look like?

@Managed
interface Product extends Named
{
    ...
}
class ProductRuleSource extends RuleSource
{
    @Model
    void products( ModelMap<Product> prods ) {}
    @Mutate
    void createTasks( ModelMap<Task> tasks, ModelMap<Product> prods )
    {
        prods.each {
            tasks.create( "generate${it.name.capitalize()}" )
        }
    }
}
apply plugin: ProductRuleSource
model {
    products {
        prodOne( Product ) {
            ...
        }
    }
}

I’d better go and test it with Gradle 2.13 and see if it makes a difference.