On 07/12/2010, at 7:43 AM, John Murph wrote:

> Another option, which also does not have support for incremental builds, is 
> to make the zip creation a function.  Then just call the function with each 
> of the different parameters.  However, I think dynamically creating the task 
> (as suggested by Etienne) might be the best option. 

I think using multiple tasks is the right way to go. In general, Gradle works 
best when you represent each atomic piece of work (such as building a zip) as a 
task, rather than combining multiple atomic pieces of work (eg building 
multiple zips) into a single task. There's a few reasons for this:

You get a lot of stuff for free: incremental build being the main thing. And 
this is more sophisticated than just checking whether some source file has 
changed and rebuilding all 4 zips. When you use multiple tasks, Gradle will 
build just the minimum that needs to be built based on what's changed. So, if 
you change one of the properties files, then just the affected zip is rebuilt, 
rather than all of the zips.

You can also build different combinations of the zips. You can exclude them. 
You can publish them. You get validation. You can profile them. And so on.

Over time you get more stuff as Gradle improves: when we add parallel task 
execution, then Gradle will be able to build each zip concurrently without you 
having to change anything. It won't be able to do this if they are combined 
into a single task. Ditto for distributed execution. Or task dependency 
autowiring. Or being able to configure tasks from the command line/user 
interface. Or having the IDE plugins hooking things up so that you can build 
the zips from the IDE.

It basically comes down to the fact that by using a task per zip, you are 
declaring more stuff about what you want to do, so that Gradle can do more for 
you. But the returns for declaring this tiny bit of extra information are well 
worth the effort, I feel.


> Tasks have groups, is there a "don't show me" group you could put the tasks 
> in so that they don't clutter a "gradle -t" list?  This would allow "private" 
> tasks, like Ant has with tasks that start with a '-'.

The default is that a task does not belong to any group. In this way, each task 
is private by default.

> 
> 
> On Fri, Dec 3, 2010 at 2:41 PM, Etienne Studer <etienne.stu...@canoo.com> 
> wrote:
> If you use the ant.zip approach in your task, you will not have support for 
> incremental builds, I believe. Just my two cents...
> 
> Etienne
> 
> 
> On 03.12.2010, at 16:53, Robert Fischer wrote:
> 
> > Since the user is never calling these things individually, I probably
> > wouldn't approach this as a bunch of tasks.  Instead, I'd probably
> > create one Gradle task to accomplish this and then use the Ant zip
> > task through the project's "ant" property.
> >
> > http://ant.apache.org/manual/Tasks/zip.html
> >
> > ~~ Robert.
> >
> >
> >
> > On 3 December 2010 09:38, richardm <richard.mur...@orchard-systems.co.uk> 
> > wrote:
> >>
> >> Is is possible to call a task in Gradle with different parameters?  I've 
> >> got
> >> a zip task which I'd like to call several times.  The project below defines
> >> a single zip task which uses a properties file to apply filters during the
> >> zip.  I need to create 4 zip files like this (the only differences are the
> >> zip names and the properties file used to filter with).  Is it possible to
> >> do this with one task and call it four times with different parameters?
> >>
> >> project(':jboss') {
> >>
> >>    Properties jboss4LiveProps = new Properties()
> >>    jboss4LiveProps.load(new
> >> FileInputStream("$projectDir/property-files/jboss4-live.properties"))
> >>
> >>    dependsOn(':otherProject')
> >>
> >>    filesToDeploy = dir('files_to_deploy')
> >>
> >>    task zipIt(type: Zip, dependsOn: filesToDeploy) {
> >>        baseName = 'jboss-4.0.2-live'
> >>        destinationDir = file("files_to_deploy")
> >>        from ('jboss-4.0.2-master') {
> >>            include "**/*.xml", "**/*.bat", "**/*.sh", "**/*properties"
> >>            filter(ReplaceTokens, tokens: jboss4LiveProps)
> >>            into 'jboss-4.0.2-live'
> >>        }
> >>        from .....
> >>
> >>    }
> >>
> >>    task build(dependsOn: 'zipIt')
> >>
> >> }
> >> --
> >> View this message in context: 
> >> http://gradle.1045684.n5.nabble.com/calling-task-multiple-times-with-different-parameters-tp3290970p3290970.html
> >> Sent from the gradle-user mailing list archive at Nabble.com.
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe from this list, please visit:
> >>
> >>    http://xircles.codehaus.org/manage_email
> >>
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list, please visit:
> >
> >    http://xircles.codehaus.org/manage_email
> >
> >
> 
> Etienne Studer
> Senior Software Developer
> 
> Canoo Engineering AG
> Kirschgartenstrasse 5
> CH-4051 Basel
> 
> T +41 61 228 94 44
> F +41 61 228 94 49
> 
> etienne.stu...@canoo.com
> www.canoo.com
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>    http://xircles.codehaus.org/manage_email
> 
> 
> 
> 
> 
> -- 
> John Murph
> Automated Logic Research Team


--
Adam Murdoch
Gradle Developer
http://www.gradle.org
CTO, Gradle Inc. - Gradle Training, Support, Consulting
http://www.gradle.biz

Reply via email to