If an external tool (such as an IDE or CI server) wishes to integrate with Gradle, they will need some way to add listeners and perhaps customize other aspects of Gradle. The approach that Ant uses for this is to pass a command line option (-listener <classname>) followed by a fully qualified class name. Ant then uses reflection to instantiate this class and registers it as a build listener. This approach is simple, but very limited. I wish to propose a more complicated, but also more powerful, approach for Gradle.
I think Gradle should provide a new command line option (--init-script <path-to-script>). Prior to even finding/loading the settings.gradle file, this script (if specified) would be executed. The script would allow tools to run Gradle and point it to a custom init script that allows for customized behavior. This script would be run with a "delegate" (similar to how the Project class is a delegate for the build script) that provides some access to Gradle as well as support for a convenience DSL. This class (InitScript.groovy?) would provide access to the startParameters (including allowing them to be modified), and support a simple DSL for instantiating classes using a custom class loader. This latter would make it easy to register a custom build listener, which is the main intended use. However, as other uses arise, more functionality could be exposed. For instance, the script might wish to examine the environment to determine that it is running in a CI server, and enable/disable specific tasks. To do this, I would assume the script would set system properties that would then be examined in the build scripts when the tasks are defined. I would like to hear of any real use cases of which you currently are aware. It would be nice to have a slightly more "complete" implementation initially, but I expect new uses to appear over time. The main problem is that because this script would execute so early in the life of the execution, many objects will not be created yet (such as the tasks in my earlier example). Some of these cases can be handled more easily than others. Does anyone have any problems or concerns with this proposal? Or, if no one can think of other uses for the script than registering build listeners, maybe the simpler Ant approach is better. -- John Murph Automated Logic Research Team
