spring-gradle-plugins / dependency-management-plugin

A Gradle plugin that provides Maven-like dependency management functionality
690 stars 88 forks source link

Provide support for the dynamic portions of the DSL when using Gradle Script Kotlin #133

Open wilkinsona opened 7 years ago

wilkinsona commented 7 years ago

The parts that use Groovy's methodMissing and propertyMissing are inaccessible (as far as I can determine) when using Kotlin. Supporting them will probably require formalising the API and providing some non-dynamic alternatives.

LDVSOFT commented 5 years ago

Hello there! Any progress here?

wilkinsona commented 5 years ago

No, sorry. Is there anything in particular that you'd like to do with Kotlin that isn't possible at the moment?

LDVSOFT commented 5 years ago

Well, I was working around Scala issue (#96, where this plugin overrides zinc configuration that should not be touched, Scala compiler uses another version of scala-library) by filtering which configurations are managed by this plugin. Since I was writing this code in Kotlin DSL, I was unable to access configurations fake method. I used methodMissing as workaround:

fun DependencyManagementExtension.forConfigurations(vararg configurations: Configuration, block: DependencyManagementConfigurer.() -> Unit) {
    // Spring does not provide better api yet

    this as StandardDependencyManagementExtension // ensure we are in root block
    methodMissing("configurations", arrayOf(*configurations, delegateClosureOf(block)))
}

// Used as:

val c = configurations.filterNot { /* ... */ }.toTypedArray()
configure<DependencyManagementExtension> { // It just means `dependecyManagement {` for plugins without Kotlin DSL support
    forConfigurations(*c) {
        imports { /*...*/ }
        dependencies { /*...*/ }
    }
}

Adding explicit methods, while even not supporting typesafe Kotlin DSL, would help a lot and make code clearer. I agree that Groovy code like

dependencyManagement {
  compile {
  }
}

looks very cool, but I would prefer to have configurations method not via methodMissing.