bamboo
08/10/2016, 2:03 PMgroovy.lang.Closure (which in Kotlin parlance would be similar to T.() -> Unit in how we use it), for compatibility with Java we also expose overloads taking an Action<T> SAM.
Now we would like Kotlin build scripts to behave as if Action<T> was T.() -> Unit to avoid the need for explicitly qualifying the single argument with it. In other words, we would like users to be writing code like copySpec { from(“src”) } instead of copySpec { it.from(“src”) }.
This could be made to work by either:
1. somehow annotating Action<T> in a way that would make the Kotlin compiler see it as equivalent to T.() -> Unit
2. declaring suitable extensions that take a T.() -> Unit and simply delegate to the Action<T> members, this would require a mechanism to tell Kotlin that those extensions should take precedence over existing members
I’m not aware of any mechanism to make Option 1 work.
Option 2 on the other hand would be possible via kotlin.internal.HidesMembers (https://github.com/JetBrains/kotlin/blob/0d26087040b94acfff0434d1a12a2975ee8accd8/libraries/stdlib/src/kotlin/internal/Annotations.kt#L46) except that it is, well, internal.
So currently it seems we’ll have to resort to [crafting a custom gradle-script-kotlin-api.jar with all offending Action<T> overloads removed](https://github.com/gradle/gradle-script-kotlin/issues/52) to be fed to the Kotlin compiler so that the T.() -> Unit extensions would actually take precedence.
Thoughts?