Rene Groeschke wrote:
> 
> Am 09.11.10 21:21, schrieb Philippe Lhoste:
>> On 09/11/2010 12:18, chris wrote:
>>> Any way I can get some re-use here?
>>
>> Not sure if that's the best way (I am a Gradle beginner) but it might
>> be a case for the task generation I saw (and wondered about the
>> usefulness) in the Getting Started page.
>>
>> Something like:
>>
>> def makeWarTask(id) {
>>     task "war$id"(type: War, dependsOn: packaging) {
>>         if (id == 1) bn = 'first' else bn = 'second'
>>         baseName = "$bn-$baseName"
>>         webInf {
>>             from fileTree("$webAppDir/WEB-INF-$id")
>>         }
>>         into ('WEB-INF/classes') {
>>             from rootProject.file('build-gradle')
>>         }
>>         into ('WEB-INF/classes') {
>>             from fileTree(sourceSets.main.classesDir)
>>             include('com/foo/web/**/*')
>>         }
>>     }
>> }
>>
>> 2.times {
>>     n -> makeWarTask(n)
>> }
>>
>> Might need some adjustments, as I know nothing about Groovy beside
>> what I learned with Gradle...
>>
> 
> to make it a bit groovier you could rewrite the above snippet to:
> -------------------
> ['first','second'].eachWithIndex{ bn, idx ->
>     task "war$idx"(type: War, dependsOn: packaging) {
>         baseName = "$bn-$baseName"
>         webInf {
>             from fileTree("$webAppDir/WEB-INF-$idx")
>         }
>         into ('WEB-INF/classes') {
>             from rootProject.file('build-gradle')
>         }
>         into ('WEB-INF/classes') {
>             from fileTree(sourceSets.main.classesDir)
>             include('com/foo/web/**/*')
>         }
>     }
> }
> 
> regards,
> René
> 

Thanks for the input guys, I think my example may have mislead you a bit
though - there's other stuff I have to change beyond the baseName and
WEB-INF location in my example, so using the inheritance-like CopySpec
overriding that Steven suggested seemed the right way for me. Dynamically
creating tasks would have started to get a little crufty for some of the
stuff I need to do (although I do use dynamic tasks in other places!).

Thanks!
Chris.

-- 
View this message in context: 
http://gradle.1045684.n5.nabble.com/Using-the-configuration-of-one-task-for-another-tp3256624p3260147.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


Reply via email to