# Dynamicall generate (native) model-component

**URL:** <https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984>\
**Category:** Help/Discuss\
**Created:** [June 6, 2015, 3:40pm UTC](https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984 "2015-06-06T15:40:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discuss.gradle.org/u/Vic)\
**Post date:** [June 6, 2015, 3:40pm UTC](https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984/1 "2015-06-06T15:40:57Z")

</div>

Porting over 10+ years of Makefiles to Gradle. Want to separate the metadata (lib/executable names, dependencies etc…) from the build script. In the following simplified example, I’m able to set the final executable name and sources dynamically.

```
model {
    components {
        hello (NativeExecutableSpec){
            baseName = mySources.executableName
            sources.c.source.srcDir mySources.srcDir
            sources.c.source.include mySources.include
        }
    } 
}   

```

How can I set ‘hello’ dynamically. It doesn’t seem to work with properties. I believe the answer lies in Chapter 66 of the Gradle 2.4 User Guide - Rule based model configuration.

If it’s too involved to give me the whole answer, could someone just please tell me that IT IS possible and maybe give me some pointers, and I will continue to plug along to figure it out.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [June 7, 2015, 5:19pm UTC](https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984/2 "2015-06-07T17:19:42Z")

</div>

Yes. In this case you can simply use a [groovy string](http://www.groovy-lang.org/syntax.html#_double_quoted_string).

```
model {
    components {
        "${mySources.componentName}"(NativeExecutableSpec)
    }
}

```

Quick tip, you can use a `GString` in this fashion in place of any method or property name in Groovy.

---

<div class="post-metadata">

**Author:** ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discuss.gradle.org/u/Vic)\
**Post date:** [June 7, 2015, 11:01pm UTC](https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984/3 "2015-06-07T23:01:04Z")

</div>

D’oh, I just needed the double-quotes. Good quick tip, too.

Thanks much!

---

<div class="post-metadata">

**Author:** ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discuss.gradle.org/u/Vic)\
**Post date:** [June 17, 2015, 3:59pm UTC](https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984/4 "2015-06-17T15:59:55Z")

</div>

Follow-up question if I may.

Now how do I dynamically set the Native component type (NativeExecutableSpec in the example) since it is neither a method nor a property.

Thanks!

---

<div class="post-metadata">

**Author:** ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discuss.gradle.org/u/Vic)\
**Post date:** [June 17, 2015, 10:05pm UTC](https://discuss.gradle.org/t/dynamicall-generate-native-model-component/9984/5 "2015-06-17T22:05:04Z")

</div>

Never mind I’m answering my own question below

def coreType = NativeExecutableSpec  
components {  
"${myBaseName}" (coreType){
