What do those constructs in gradle.build really mean?

I have created a basic gradle build. My build scripts contain constructs such as:

subprojects {
  group = 'tld.example'
  version = '0.1'
}

I deciphered this one: Build script is delegating all calls to Project object, and subprojects is just a method defined on that object, which accepts a Closure.

Easy enough. But what does this one mean?

model {
  components {
    foo(NativeLibrarySpec) {
      sources {
        cpp {
          source {
            srcDir "src"
            include "**/*.cpp"
          }
          exportedHeaders {
            srcDirs "${rootDir}/include"
          }
        }
      }
    }
  }
}

Fair enough, it is bit longer than the previous snippet, so namely:

  • I have a bit of trouble to follow the context, while going all the way down from model to e.g. source
  • I am quite certain there is no foo method/property defined on anything, so what am I actually calling/doing by saying foo(NativeLibrarySpec)? Wild guess would be that groovy has some PHP-like magic functions, which will handle this?

Note: I have asked this same quesiton on StackOverflow some time ago, but without any success, so I am asking the same thing right at the source.

In groovy it’s possible to implement a methodMissing(String name, Object[] args) method to catch invocations not known at compile time. I believe this is where most of gradle’s DSL magic is implemented.

Is there a way to find what that model and components is? It should then contain methodMissing handling my foo, right?

Hmm… Looking through the source code it seems I was wrong about methodMissing.

The native plugins use the new rule based model configuration.

I’m not familiar with how this mechanism works sorry