This message was deleted.
# community-support
s
This message was deleted.
t
always use
Action
if you use Kotlin DSL, Gradle will convert it to lambda-with-receiver at runtime, so it's identical to using a lambda anyway this is in your public API. Internally, use whatever you want
e
OK thanks, I though that was the case, but I see that Gradle uses lambdas in
org.gradle.kotlin.dsl
so I wasn't 100% sure
Is it OK to use default params in the public API, e.g.
Copy code
public fun Foo(action: Action<Bar> = Actions.doNothing())
t
I'm not sure Groovy DSL would understand that. Maybe with
@JvmOverloads
?
👍 1
e
In either case, that would only be an issue if I tried to use that API from a Groovy script, right?
t
presumably
e
OK thanks!
g
IIRC Gradle works with actions just fine from groovy dsl
j
Yeah gradle ships some nice interop glue. I have used this to be able to expose groovy closures as typed lambdas in kotlin outside of the gradle context:
Copy code
fun <T> Any.closureOf(action: T.() -> Unit): Closure<Any?> = 
     KotlinClosure1(action, this, this) 
  
 /** 
  * Adapts an unary Kotlin function to an unary Groovy [Closure]. 
  * 
  * @param T the type of the single argument to the closure. 
  * @param V the return type. 
  * @param function the function to be adapted. 
  * @param owner optional owner of the Closure. 
  * @param thisObject optional _this Object_ of the Closure. 
  * 
  * @see [Closure] 
  */ 
 class KotlinClosure1<in T : Any?, V : Any>( 
     val function: T.() -> V, 
     owner: Any? = null, 
     thisObject: Any? = null 
 ) : Closure<V?>(owner, thisObject) { 
  
     @Suppress("unused") // to be called dynamically by Groovy 
     fun doCall(it: T): V = it.function() 
 }