hi Hans,
Firstly, thanks for gradle, i think it's great. I need some help
understanding how varable scoping works in gradle.
I've got some problems defining variables/tasks in the allprojects{} or
subprojects{} groups. When resolving variables, it seems that the last
project's variables are the ones that are resolved. Simple example follows:
// Copies the distrobution jar(s) to the collective distro directory
Closure distro = { task ->
println "copy $task.project.name to colective"
task.project.libs.archiveNames.each {archiveName ->
ant.copy(file: task.project."$archiveName".archivePath, todir:
'collective')
}
}
Closure simplePrint = { task ->
println "i work when called directly, $task.project.name"
}
subprojects {
usePlugin('java')
type='jar'
sourceCompatibility = 1.5
targetCompatibility = 1.5
version='1.0'
createTask('printTest', simplePrint)
createTask('distro', distro)
task('libs').doLast {
task('distro').execute()
}
createTask("copyDist", dependsOn:'distro') {
}
}
project(':subProjectA') {
srcDirNames = ['']
}
project(':subProjectB') {
srcDirNames = ['']
}
http://www.nabble.com/file/p18312735/example.tgz example.tgz
When I execute libs, the 'distro' task will always print out "copy
subProjectB to colective", and subProjectA's jar will not be in the
directory. It works correctly if i execute task 'copyDist' (both jars are
copied). The 'printTest' task also works as expected.
My problem is that i cannot always use the dependsOn method as I have some
complex build requirements. It will make the build file a lot shorter and
more elegant if I could count on variable scoping.
It basically boils downto this: I cannot create tasks in the root project
that behaves differently when executed by subprojects based on certain
criteria (variables).
Regards,
Pieter
--
View this message in context:
http://www.nabble.com/Gradle-variable-scope-tp18312735p18312735.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