Kotlin-dsl-samples: repositories { maven { url = "https://example.com" } }

Created on 11 Oct 2018  路  3Comments  路  Source: gradle/kotlin-dsl-samples

When I rename a build.gradle of an existing project to build.gradle.kts, there is a leap of faith, a moment where the IDE is useless, where I need to reach as fast as possible the point where ./gradlew tasks succeeds.

In this context, the repositories configuration gets in the way for dumb reasons.

Expected Behavior

Ideally, that syntax would work in both groovy and kotlin

repositories {  
    mavenCentral()
    maven { url "https://example.com" } }
}

Current Behavior

  • maven { url "https://example.com" } } does not work
  • maven { url = "https://example.com" } } does not work either

This has bad side effects: if you have a buildscript blog, the plugins won't get resolvec, etc..

The current "solution" is maven { setUrl("https://example.com") } }, which

  • works
  • is not trivial to discover
  • is not really nice
  • is inconsistent with the nicer mavenCentral() and friends

Possible solution

Make this a valid syntax (see first comment)

repositories {  
    maven("https://example.com")
}

Context & Steps to reproduce

See intro

Your Environment

IntelliJ or Android Studio

All 3 comments

Here is a sample implementation for

repositories {  
    maven("https://example.com")
}
fun RepositoryHandler.maven(
    url: String,
    name: String? = null,
    username: String? = null,
    password: String? = null,
    configureIvy: Action<in IvyArtifactRepository>? = null
) {
    this.maven {
        setUrl(url)
        if (name != null) setName(name)
        if (username != null && password != null) {
            credentials {
                setUsername(username)
                setPassword(password)

            }
        }
        if (configureIvy != null) ivy(configureIvy)
    }
}

Oh nice!

Was this page helpful?
0 / 5 - 0 ratings