On 17/02/10 8:01 PM, Peter Ledbrook wrote:
Hi,

I have two custom tasks provided by a plugin in which one absolutely
depends on the other. The skeleton of the structure is like so:

   task("buildData") {
       appName = "unspecified"
       appVersion = project.version
       grailsVersion = "unspecified"
       servletContext = appName
       servletVersion = "2.4"
       doLast {
           ...
       }
   }

   class GrailsPluginsTask extends DefaultTask {
       @TaskAction
       void execute() {
           // Some sort of reference to buildData here.
           project.buildData.grailsVersion
       }
   }

What's the best way of connecting the two? The first task loads some
configuration files and provides some of the data therein as task
properties. The second task needs to access those properties in order
to do its work.

Should GrailsPluginsTask have a hard-coded dependsOn? Or should I link
the two in the plugin?

It depends :)

We make the built-in Gradle tasks independent of each other and the plugins, so that they can be reused in different contexts - with or without the plugin. The plugin takes care of injecting the configuration into each task. The dependencies are almost entirely taken care of by the dependency auto-wiring, so the plugin almost never needs to use dependsOn(). Of course, this is slightly more effort than just hard-coding the references in the tasks.

If you don't ever intend that the tasks are reusable outside the plugin, you could hard-code the references.

Given the example above, I would suggest moving the configuration to a convention object which the tasks share. This convention object would have properties like appName, appVersion, grailsVersion, etc.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email


Reply via email to