>> Is is possible to call a task in Gradle with different parameters?
>>> 1) Task rules could be one approach.
>>> 2) Or, you could dynamically create four tasks. Iterate over a list of
>>> 'parameters' and dynamically
>>> create a task for each element. See a sample below (the content of the
>>> Zip task is not complete and >>> not relevant for this example):
I opted for the dynamic tasks approach. I use a list of property file names
to loop round, and use the name to load a different properties file required
for my filter.
['jboss4-live', 'jboss4-demo', 'jboss4-test', 'jboss4-trng'].each { def
propertyName ->
//create dynamic tasks
tasks.add(name: "zipIt$propertyName", type: Zip, dependsOn:
[filesToDeploy, copyBaseWar, copyServerLogWar, copyOrchardFiles]) {
//load properties file for jboss environment (used by filter
below)
Properties props$propertyName = new Properties()
props$propertyName.load(new
FileInputStream("$projectDir/property-files/" + propertyName +
".properties"))
jbossType = props$propertyName.getProperty('JBOSSTYPE')
baseName = jbossType
destinationDir = file("$projectDir/files_to_deploy")
//'from' is split into 2 steps so we can apply filters to a
limited set of file (.xml, .bat, .sh, .properties).
from ('jboss-4.0.2-master') {
include "**/*.xml", "**/*.bat", "**/*.sh", "**/*properties"
filter(ReplaceTokens, tokens: props$propertyName)
into jbossType
}
from ('jboss-4.0.2-master') {
//exclude the files already copied (and filtered) in above
step
exclude "**/*.xml", "**/*.bat", "**/*.sh", "**/*properties"
rename 'JavaService.exe',
props$propertyName.getProperty('SYSTEMTYPE') + ".exe"
into jbossType
}
}
}
This works great, but I'm not clear on how this could be done using Task
rules. I've read the documentation on task rules but don't understand it as
their's only one example. Can anyone explain task rules in more detail or
provide examples?
>> I think using multiple tasks is the right way to go.
Adam, when you say multiple tasks, do you agree with the dynamic tasks
approach?
--
View this message in context:
http://gradle.1045684.n5.nabble.com/calling-task-multiple-times-with-different-parameters-tp3290970p3300004.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