I am getting started with using the kotlin-dsl in ...
# gradle
e
I am getting started with using the kotlin-dsl in an android project and I’m a bit surprised that I have to use
Copy code
buildTypes {
  getByName("debug") {
  ...
  }
}
instead of
Copy code
buildTypes {
  "debug" {
  ...
  }
}
I can see a
NamedDomainObjectContainerScope
that defines the
String.invoke
extension but I’m not able to use it without explicitly specifying
Copy code
buildTypes.invoke {
  "debug" {
  ...
  }
}
(possibly because the android plugin defines
fun buildTypes(Action<BuildType>)
). Is there a way to force the script to look like the second snippet above? (I believe Kotlin JVM had an annotation that would give the object extension more priority over the object member 🤔)
j
The first syntax seems more "easy" for you because you are familiar with it, but I would argue that the second one is more "simple". Explicit is better than implicit