Given a DSL that is defined by an external project...
# announcements
j
Given a DSL that is defined by an external project (Gradle in my case), is it possible to define an extension function
fun String.someExtensionFunction() = "Hello World"
that would be usable only from the right extension block?
Copy code
dependencies { // this is Dependencies
    ....
}
That seems impossible because it would require to define the function having two receivers,
Dependencies
and
String
d
You can wrap the dependencies with your own class, using interface delegation. Then add your function to the class.
class MyReceiver(deps: Dependencies) : Dependencies by deps) { fun String.function()... } Then create your own dependencies {} function with a slightly different name
j
That's a clever trick
k