# Question around rule source example

**URL:** <https://discuss.gradle.org/t/question-around-rule-source-example/10776>\
**Category:** Help/Discuss\
**Created:** [July 23, 2015, 9:21pm UTC](https://discuss.gradle.org/t/question-around-rule-source-example/10776 "2015-07-23T21:21:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ante\_Ilic1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ante_ilic1/32/2582_2.png) [@Ante\_Ilic1](https://discuss.gradle.org/u/Ante_Ilic1)\
**Post date:** [July 23, 2015, 9:21pm UTC](https://discuss.gradle.org/t/question-around-rule-source-example/10776/1 "2015-07-23T21:21:31Z")

</div>

Hi,

I was trying to incorporate part of an example from the new nightly build into my build file but I get this error when I try to use it:  
Exception thrown while executing model rule: model.tasks

> $() syntax cannot be used when model {} block is not a top level statement in the script

```
apply plugin: 'cpp'
    model {
        components {
            someLib (NativeLibrarySpec) {
                sources {
                    targetPlatform "macosx32"
                    flexOutput(CppSourceSet) {
                        generatedBy tasks.flex
                        generatedBy tasks.bison
                        source {
                            include "**/*.cpp"
                        }
                        exportedHeaders {
                            srcDirs "some header dir"
                        }
                    }
    
                    bisonOutput(CppSourceSet) {
                        generatedBy tasks.bison
                        source {
                            include "**/*.cpp"
                        }
                        exportedHeaders {
                            srcDirs "some header"
                        }
                    }
    
                    cpp.lib sources.bisonOutput
    
                    cpp.lib sources.flexOutput
                    cppSource(CppSourceSet) {
                        source {
                            srcDirs "sourceDir"
                        }
                        exportedHeaders{
                            srcDirs "header dir"
                        }
                    }
    
                }
    
                binaries.all {
                    cppCompiler.define "some defines"
                    cppCompiler.args "some flags"
                }
            }
        }
        tasks { t ->
            $("components.hlslang").binaries { binaries ->
                binaries.values().each { binary ->
                    def stripTask = "strip${binary.name.capitalize()}"
                    t.create(stripTask) {
                        dependsOn binary.tasks.link
                        doFirst {
                            print binary.metaClass.methods*.name.sort().unique() + "\n"
                        }
                    }
                }
            }
        }

```

this is part of my build file, later I have toolchains, platforms and buildtypes defined. I also have some custom tasks in there.  
My question is what I am doing wrong?

Regards,  
Ante

---

<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:** [July 24, 2015, 9:04am UTC](https://discuss.gradle.org/t/question-around-rule-source-example/10776/2 "2015-07-24T09:04:32Z")

</div>

The reported error is a bit of a red herring. The use of the `$()` syntax is hidden behind a feature toggle. You’ll have to add `-Dorg.gradle.model.dsl=true` to the command line in order to use it.

---

<div class="post-metadata">

**Author:** ![Ante\_Ilic1](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ante_ilic1/32/2582_2.png) [@Ante\_Ilic1](https://discuss.gradle.org/u/Ante_Ilic1)\
**Post date:** [July 24, 2015, 9:15am UTC](https://discuss.gradle.org/t/question-around-rule-source-example/10776/3 "2015-07-24T09:15:06Z")

</div>

Thanks Mark, forgot about that one 🙂
