Steven Devijver wrote:
Hey,

I'm using the latest Gradle HEAD and I'm experiencing an unexpected behavior with the subprojects { } method:

subprojects {
if (name.startsWith('spring-')) {

assert name == "spring-core"
configurations {

moduleJars
sources
archives
}

dependencies {
moduleJars project('java14')
moduleJars project('java15')
}
task files << {
configurations.moduleJars.files.each { file -> println file.name }
}


task moduleJar(type: Jar) {
destinationDir = file('build/jar_for_module')
}
artifacts {
archives moduleJar
}
task uploadArchives(type: Upload) {
dependsOn moduleJar

configuration = configurations.archives
repositories {
  flatDir(dirs: dist_dir)
}
}
moduleJar.doFirst {
assert configurations.ivyService.ivyService.ivyService.metaDataProvider.module.name == "spring-core"
for (jar in configurations.moduleJars.files) {
moduleJar.merge(jar)
}
}
}
}

The second assert (the one in the moduleJar task) fails while the first assert works. Is this as expected? I got the same result with Gradle 0.8.

This problem comes about whenever you have a closure inside subprojects { } which is not executed straight away. For example, the task action closures above do not execute until the task executes. By the time the task action closure executed, the delegate of the subprojects {} closure is no longer pointing to the task's project, instead it points to the last subproject. This means that property and method references in the closures will be executed against the last subproject, rather than the task's project.

Could you add a JIRA issue for this problem?

A work around is to do something like:

moduleJar.doFirst { task ->
  for (jar in task.project.configurations.moduleJars.files) {
      ....
  }
}



I've added these asserts because configurations.moduleJars is throwing an expection saying the moduleJars property is not found.

I've uploaded the entire project for download here:

http://3.ly/I7W


Thanks for your help

Steven


--
Adam Murdoch
Gradle Developer
http://www.gradle.org

Reply via email to