This document is a very first draft based on the experience with Groovy.
Required
- The script engine is responsible for executing the build script. It should be capable of delegating methods and properties not defined in the build script to a Java project object (which is passed to the build script engine from the gradle-core).
- Methods of the script engine needs to be callable from Java.
Optional
Some of the optional features are at the heart to provide a convenient DSL. If you just take the required features into account you could easily write a Java build script engine. But this build script would be rather hard to read and maintain.
- Something like an AntBuilder to provide easy integration of Ant tasks.
- Closures to define actions and do configuration. With actions this only works, if it is possible to coerce closures to objects of anonymous Java classes (e.g. of type Action, which is an interface). For the configuration it needs to be possible to set a Java class as the delegate of the closure. It is of course possible to live for example without configuration closures. But it makes it less convenient to write a build script.
In this example we have a dependencies method which takes a closure as an argument and set's a Java object as a delegate of this closure. When executing the closure, the method addMavenRepo of the delegate is called.
dependencies { addMavenRepo() // do more } - The script engine should be able to provide something like a proxy around 2 or 3 gradle-core classes. This proxy would be responsible for doing the DSL magic. For example it is possible in Gradle to access a task like this:
With the Groovy script engine we have subclassed the gradle-core class with a Groovy class. This Groovy class has a
createTask('hello') { // something } hello.doFirst { // something }methodMissingmethod, which looks amongst other things if the name of the missing method correspond to a task name. If sotask('hello')of the gradle-core class is called.
Labels:
