Since #914 we generate kotlin extensions for the Gradle API mapping Groovy named arguments to Kotlin vararg of Pair.
This is not ideal. It would be nice if the Gradle methods taking Groovy named arguments were annotated with metadata about the name and type of expected arguments, allowing us to generate more type-safe kotlin extensions.
For example:
public void apply(@NamedArguments(ObjectConfigurationAction.class) Map<String, ?> options);
Or, more generally:
interface SomeInterface {
interface NamedArgumentsForFunction {
void name(String stringArgument);
void type(@Nullable Class<?> classArgument);
// etc...
}
...
public void function(@NamedArguments(NamedArgumentsForFunction.class) Map<String, ?> options);
}
So we can enhance the code generator to emit overloads such as:
fun SomeInterface.function(name: String, type: Class<*>? = null, vararg options: Pair<String, Any?>) =
function(mapOf("name" to name, "type" to type, *options))
We should also consider not offering these overloads at all. They often just add unnecessary way of doing things differently. The Kotlin DSL is a great opportunity to undo some of those mistakes.
Most helpful comment
We should also consider not offering these overloads at all. They often just add unnecessary way of doing things differently. The Kotlin DSL is a great opportunity to undo some of those mistakes.