[Rule base model configuration] `@Defaults` document is incorrect

Hi. I have tried a brand new rule base model configuration via http://gradle.org/docs/2.4/userguide/new_model.html. I found that the order of method execution is different from api document. I think @Defaults's document is incorrect on order of method execution.

it says

Default rules execute after Model rules (i.e. after the element is created), but before Mutate rules. The first parameter of the rule is the rule subject, which is mutable for the duration of the rule.

But the order of @Default method is executed before @Model method.

I wrote.

class SampleRule extends RuleSource {

    void sampleModel(SampleModel sm) {
        println "@Model method[from: ${sm.from}, into: ${sm.into}]"

    void defaultsMethod(SampleModel sm) {
        println "@Defaults method[from: ${sm.from}, into: ${sm.into}]"

    void create(CollectionBuilder<Task> tasks, SampleModel sm) {
        println "@Mutate create[from: ${sm.from}, into: ${sm.into}]"
        tasks.create('sampleRule') {
            group = 'sample-rule'
            doLast {
                println "from [${sm.from}] into [${sm.into}]"
public interface SampleModel {

    void setFrom(String from);
    String getFrom();

    void setInto(String into);
    String getInto();

build script is bellow.

model {
    sampleModel {
        from = 'here'
        into = 'there'

And the result is bellow.

$ gradle sampleRule
@Defaults method[from: null, into: null]
@Model method[from: null, into: null]
@Mutate create[from: here, into: there]
from [here] into [there]

This is apparently expected according to one of the Gradle engineers in this workshop. It’s counter-intuitive, but Gradle apparently creates the managed model element by inspecting the @Model method, not by executing it. Then the defaults are applied, and then the @Model method is actually executed.

In other words, the behaviour you’re seeing is intentional. I don’t know why that’s the case though.