When converting a JavaExec task from groovy to Kot...
# gradle
e
When converting a JavaExec task from groovy to Kotlin I had to add an explicit
get()
, because
main
references a
NamedDomainObjectProvider<SourceSet>
and not an actual SourceSet:
Copy code
task foo(type: JavaExec) {
	classpath sourceSets.main.runtimeClasspath
has become
Copy code
tasks.create<JavaExec>("foo") {
	classpath = sourceSets.main.get().runtimeClasspath
Couple of questions about that: • Have I now changed the behavior from lazy to eager configuration? • How does groovy do this magic (i.e. why can I use runtimeClassPath on a Provider)? • Is there any cleaner way to do this?
o
1) no, create is still eager, register is the lazy one 2) special method called invokeMethod, see http://docs.groovy-lang.org/latest/html/documentation/core-metaprogramming.html#_invokeMethod, gradle probably tries to delegate calls to the result of get() 3) I think this is pretty clean as is, although if you don't like the extra get you can do
sourceSets["main"].runtimeClasspath
instead
I see that I read (1) backwards, but the answer is still no. Original calls create too iirc.
e
Thanks for the answer! My question 1) was a little ambiguous. I meant to ask about
sourceSets.main.runtimeClasspath
in Groovy versus
sourceSets.main.get().runtimeClasspath
in Kotlin. Does the first also resolve the sourceSet eagerly?