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

**URL:** <https://discuss.gradle.org/t/rule-base-model-configuration-defaults-document-is-incorrect/9681>\
**Category:** Bugs\
**Created:** [May 19, 2015, 6:44am UTC](https://discuss.gradle.org/t/rule-base-model-configuration-defaults-document-is-incorrect/9681 "2015-05-19T06:44:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shinya\_Mochida](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/shinya_mochida/32/2393_2.png) [@Shinya\_Mochida](https://discuss.gradle.org/u/Shinya_Mochida)\
**Post date:** [May 19, 2015, 6:44am UTC](https://discuss.gradle.org/t/rule-base-model-configuration-defaults-document-is-incorrect/9681/1 "2015-05-19T06:44:26Z")

</div>

Hi. I have tried a brand new rule base model configuration via [Chapter&nbsp;66.&nbsp;Rule based model configuration](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](http://gradle.org/docs/current/javadoc/org/gradle/model/Defaults.html) is incorrect on order of method execution.

[it](http://gradle.org/docs/current/javadoc/org/gradle/model/Defaults.html) 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.

```groovy
class SampleRule extends RuleSource {

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

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

    @Mutate
    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}]"
            }
        }
    }
}
@Managed
public interface SampleModel {

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

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

```

build script is bellow.

```groovy
model {
    sampleModel {
        from = 'here'
        into = 'there'
    }
}

```

And the result is bellow.

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

```

---

<div class="post-metadata">

**Author:** ![pledbrook](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/pledbrook/32/1101_2.png) [@pledbrook](https://discuss.gradle.org/u/pledbrook)\
**Post date:** [November 25, 2015, 5:16pm UTC](https://discuss.gradle.org/t/rule-base-model-configuration-defaults-document-is-incorrect/9681/2 "2015-11-25T17:16:14Z")

</div>

This is apparently expected according to one of the Gradle engineers in [this workshop](https://gradle.org/rule-based-model-configuration-workshop-part-1/). 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.
