Reputation: 4676
First off, this is my first foray into Gradle/Groovy (using Gradle 1.10). I'm setting up a multi-project environment where I'm creating a jar artifact in one project and then want to define an Exec task, in another project, which depends on the created jar. I'm setting it up something like this:
// This is from the jar building project
jar {
...
}
configurations {
loaderJar
}
dependencies {
loaderJar files(jar.archivePath)
...
}
// From the project which consumes the built jar
configurations {
loaderJar
}
dependencies {
loaderJar project(path: ":gfxd-demo-loader", configuration: "loaderJar")
}
// This is my test task
task foo << {
configurations.loaderJar.each { println it }
println configurations.loaderJar.collect { it }[0]
// The following line breaks!!!
println configurations.loaderJar[0]
}
When executing the foo
task it fails with:
> Could not find method getAt() for arguments [0] on configuration ':loaderJar'.
In my foo
task I'm just testing to see how to access the jar. So the question is, why does the very last println fail? if a Configuration object is a Collection/Iterable then surely I should be able to index into it?
Upvotes: 0
Views: 483
Reputation: 123920
Configuration
is-a java.util.Iterable
, but not a java.util.Collection
. As can be seen in the Groovy GDK docs, the getAt
method (which corresponds to the []
operator) is defined on Collection
, but not on Iterable
. Hence, you can't index into a Configuration
.
Upvotes: 2