Discussion:
defining a task based on another pre-configured task
Robert Fletcher
2012-12-21 00:48:57 UTC
Permalink
Hi

I'm doing several very similar Exec tasks which only vary based on their
`workingDir`. The `commandLine` is the same in each case and incremental
build inputs & outputs are a function of the `workingDir`. Instead of
repeating myself is there a way I can define a new task as a pre-configured
Exec task?

Sorry if that's confusing. The build I'm talking about is here:
https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15

Rob
Justin Ryan
2012-12-21 00:55:09 UTC
Permalink
How 'bout:

['standard', 'nonStandard', 'customDir'].each { target ->
task("init${target.capitalize()}DirProject", type: Exec) {
workingDir "src/test/resources/projects/${target}"
commandLine 'bower', 'install'
inputs.files new File(workingDir, 'component.json')
outputs.files new File(workingDir, 'web-app')
}
}


On Thu, Dec 20, 2012 at 4:48 PM, Robert Fletcher <
Post by Robert Fletcher
Hi
I'm doing several very similar Exec tasks which only vary based on their
`workingDir`. The `commandLine` is the same in each case and incremental
build inputs & outputs are a function of the `workingDir`. Instead of
repeating myself is there a way I can define a new task as a pre-configured
Exec task?
https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15
Rob
Luke Daley
2012-12-21 02:08:21 UTC
Permalink
Another option is to not subclass Exec, but use project.exec {} in your own implementation.

We are aware that this kind of composition can be awkward and have some long term plans to improve the situation.
Post by Justin Ryan
['standard', 'nonStandard', 'customDir'].each { target ->
task("init${target.capitalize()}DirProject", type: Exec) {
workingDir "src/test/resources/projects/${target}"
commandLine 'bower', 'install'
inputs.files new File(workingDir, 'component.json')
outputs.files new File(workingDir, 'web-app')
}
}
Hi
I'm doing several very similar Exec tasks which only vary based on their `workingDir`. The `commandLine` is the same in each case and incremental build inputs & outputs are a function of the `workingDir`. Instead of repeating myself is there a way I can define a new task as a pre-configured Exec task?
Sorry if that's confusing. The build I'm talking about is here: https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15
Rob
TheKaptain
2012-12-21 07:18:49 UTC
Permalink
You should be able to do something like this as well if you prefer:

def configureExec = { task, projectName, outputDir, cmdLine = ['bower,
install'] ->
task.workingDir "src/test/resources/projects/$projectName"
task.commandLine cmdLine
task.inputs.files file("${task.workingDir}/component.json")
task.outputs.files file("${task.workingDir}/$outputDir")
}

task initStandardProject(type: Exec){ task ->
configureExec(task, 'standard', 'components')
}

task initCustomDirProject(type: Exec){ task ->
configureExec(task, 'customDir', 'web-app')
}

task initNonStandardProject(type: Exec){ task ->
configureExec(task, 'nonStandard', 'lib', ['bower', 'install',
'--directory=lib'])
}

processTestResources.dependsOn initStandardProject
processTestResources.dependsOn initNonStandardProject
processTestResources.dependsOn initCustomDirProject




--
View this message in context: http://gradle.1045684.n5.nabble.com/defining-a-task-based-on-another-pre-configured-task-tp5710571p5710576.html
Sent from the gradle-user mailing list archive at Nabble.com.
Robert Fletcher
2012-12-21 09:07:24 UTC
Permalink
Thanks for the help, guys. I have a solution in place now based on Justin's
suggestion.
https://github.com/robfletcher/gazebo/blob/master/build.gradle#L15
Post by TheKaptain
def configureExec = { task, projectName, outputDir, cmdLine = ['bower,
install'] ->
task.workingDir "src/test/resources/projects/$projectName"
task.commandLine cmdLine
task.inputs.files file("${task.workingDir}/component.json")
task.outputs.files file("${task.workingDir}/$outputDir")
}
task initStandardProject(type: Exec){ task ->
configureExec(task, 'standard', 'components')
}
task initCustomDirProject(type: Exec){ task ->
configureExec(task, 'customDir', 'web-app')
}
task initNonStandardProject(type: Exec){ task ->
configureExec(task, 'nonStandard', 'lib', ['bower', 'install',
'--directory=lib'])
}
processTestResources.dependsOn initStandardProject
processTestResources.dependsOn initNonStandardProject
processTestResources.dependsOn initCustomDirProject
--
http://gradle.1045684.n5.nabble.com/defining-a-task-based-on-another-pre-configured-task-tp5710571p5710576.html
Sent from the gradle-user mailing list archive at Nabble.com.
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Loading...