Kotlin-dsl-samples: Provide maven(url: String, name: String? = null, ...) shortcut

Created on 26 Jan 2017  路  6Comments  路  Source: gradle/kotlin-dsl-samples

Current syntax to specify Maven repositories is not very idiomatic. Providing a regular Kotlin maven()function with parameters like maven(url: String, name: String? = null, ...) would be more easy to use for end users via autocomplete, positional or named parameters, and would read and write more easily.

Current syntax:

repositories {
  maven { setUrl("...") }
}
````

Proposed syntax:
```kotlin
repositories {
  maven(url = "...") // can be abbreviated to maven("...")
}
chore gradle-api ease-of-use groovy-parity

Most helpful comment

We should reconsider this shortcut.

All 6 comments

Alternatively we could add the strongly typed setter setUrl(URI) to MavenArtifactRepository and then the syntax would be:

maven { url = uri("...") }

As a second step we could work with the Kotlin team to introduce the concept of implicit conversion compiler plugins and achieve complete parity with Groovy with the advantage of compile time checking:

maven { url = "..." } // statically checked implicit conversion from String to URI 

I like the alternative route a lot.

We should refrain from adding adhoc shortcuts. They are terrible to maintain, they may outnumber us at some point 馃槃 and they surely will minimize the goodness we could get from a coherent frontend on top of the Gradle API.

Type safe setters have been added to the Gradle API in:

  • MavenArtifactRepository
  • IvyArtifactRepository
  • MavenPluginRepository
  • IvyPluginRepository

See https://github.com/gradle/gradle/issues/1823

This provides the following:

repositories {
  maven { url = uri("...") }
}

Implicit conversions will be addressed in https://github.com/gradle/gradle-script-kotlin/issues/335

As commented on gradle#335, I am against introducing implicit conversion to Kotlin, and I still think such shortcut is relevant for such frequently used statement.

We should reconsider this shortcut.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredsburrows picture jaredsburrows  路  3Comments

iNikem picture iNikem  路  3Comments

AlexCzar picture AlexCzar  路  3Comments

jaredsburrows picture jaredsburrows  路  3Comments

wuchengithub picture wuchengithub  路  4Comments