# Gradle rule-based model nested beans syntax

**URL:** <https://discuss.gradle.org/t/gradle-rule-based-model-nested-beans-syntax/14825>\
**Category:** Help/Discuss\
**Tags:** software-model, plugins\
**Created:** [February 29, 2016, 3:23pm UTC](https://discuss.gradle.org/t/gradle-rule-based-model-nested-beans-syntax/14825 "2016-02-29T15:23:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhead](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/madhead/32/2108_2.png) [@madhead](https://discuss.gradle.org/u/madhead)\
**Post date:** [February 29, 2016, 3:23pm UTC](https://discuss.gradle.org/t/gradle-rule-based-model-nested-beans-syntax/14825/1 "2016-02-29T15:23:20Z")

</div>

I want to try new rule based configuration in Gradle to configure my plugin. Plugin’s purspose is uploading data to cloud storages, like Google Drive or S3. I need a configuration for each storage the user want’s to use. So, what I want to achieve is:

```
model {
    backup { // this is a container for all storages I want to support
        googleDrive {
            clientId = ''
            clientSecret = ''
            accessToken = ''
            refreshToken = ''
        }

        s3 {
           // S3 specific config (like API keys)
        }
    }
}

```

In my plugin I configure rule source for backup element:

```
class BackupPlugin implements Plugin<Project> {

    static class Rules extends RuleSource {
        @Model
        void backup(BackupPluginExtension backupModel) {}
    }
}

@Managed
interface BackupPluginExtension {
    GoogleDrive getGoogleDrive()

    void setGoogleDrive(GoogleDrive googleDrive)
}

@Managed
interface GoogleDrive {
    String getClientId()

    void setClientId(String clientId)

    String getClientSecret()

    void setClientSecret(String clientSecret)

    String getAccessToken()

    void setAccessToken(String accessToken)

    String getRefreshToken()

    void setRefreshToken(String refreshToken)
}

```

But, that doesn’t work saying: `Could not find method googleDrive() for arguments [build_8w85xu7hrz3atgeg839d33hzl$_run_closure1_closure2_closure3@1b06ac95] on root project 'test'.`. Looks like it tries to call methods inside backup and not configure nested beans.

So, what is the correct syntax for that?

---

<div class="post-metadata">

**Author:** ![axl](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/axl/32/834_2.png) [@axl](https://discuss.gradle.org/u/axl)\
**Post date:** [April 11, 2016, 5:58am UTC](https://discuss.gradle.org/t/gradle-rule-based-model-nested-beans-syntax/14825/2 "2016-04-11T05:58:26Z")

</div>

For managed sub-types, if you want Gradle to instantiate the object, you need to not supply a setter. It’s not entirely clear to me how to use this if one has a setter, but in your case I’m pretty sure it’ll work if you just omit it.

```gradle
@Managed
interface BackupPluginExtension {
    GoogleDrive getGoogleDrive()
}

```

---

<div class="post-metadata">

**Author:** ![madhead](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/madhead/32/2108_2.png) [@madhead](https://discuss.gradle.org/u/madhead)\
**Post date:** [April 11, 2016, 8:06am UTC](https://discuss.gradle.org/t/gradle-rule-based-model-nested-beans-syntax/14825/3 "2016-04-11T08:06:27Z")

</div>

Well, the problem was Gradle version. Looks like some bug in 2.9. In latest version everything works with or without setter. The question is already answered [here](http://stackoverflow.com/a/36297735/750510).
