On 12/03/2011, at 4:08 AM, Mikael Andersson wrote:

> Hi
> 
> I'm wondering if it is possible to have conditional execution of the
> configuration closure?
> I'm currently trying to write a simple release plugin which sets up
> tasks for taging, branching, uploadingArchive, bumbing version number,
> committing, and some other stuff.
> 
> I'd like this plugin to be applied to all our "components" but
> currently I'm not quite sure how I can achieve that because when I'm
> declaring for example the svn copy task it uses parameters which
> aren't available unless one is wanting to execute that task.
> 
> For example in my plugins apply method I've got
> 
> project.task([type:SvnCopyTask], 'tagRelease){
> message = project.tagMessage
> src = project.svnSrc
> dest = project.svnDest
> }
> 
> I'm pretty sure I'm missing something fundamental, how should I code
> such a task configuration?

There's no really good option, yet. Here are some possibilities:

* Configure the task in the afterEvaluate { } method:

def copyTask = project.task('tagRelease', type: SvnCopyTask)
project.afterEvaluate { 
    copyTask.configure { 
        message = ...
    }
}

* Use a 'convention mapping':

def copyTask = project.task('tagRelease', type: SvnCopyTask)
copyTask.conventionMapping.message = { project.tagMessage }
copyTask.conventionMapping.src = { project.svnSrc }

Both of these approaches currently have some issues, but mostly work ok. We use 
the second approach pretty extensively in the built-in Gradle plugins.

One option which has been discussed, but which is a major breaking change, is 
that we change Gradle so that it will only execute the configuration closure 
when the task is selected for execution, ie when it is added to the DAG. This 
would mean that your code above would work as-is.


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
Co-Founder and VP of Engineering, Gradleware Inc. - Gradle Training, Support, 
Consulting
http://www.gradleware.com

Reply via email to