How to add a maven repository by url using kotlinscript DSL (build.gradle.kts)

Whats the equivalent of the following code snippet from a build.gradle in a build.gradle.kts version?

repositories {
  mavenCentral()
  maven {
    url '<MAVEN REPO URL>'
  }
}

3 answers

  • answered 2018-01-13 17:31 Florian Reisinger

    At 2018-01-13 the correct syntax is the following (instad of url, the function setUrl):

    repositories {
        mavenCentral()
        maven {
            setUrl("<MAVEN REPO URL>")
        }
    }
    

  • answered 2018-01-13 17:31 s1m0nw1

    It’s also possible to do it like this:

    repositories {
        mavenCentral()
        maven {
            url = uri("<MAVEN REPO URL>")
        }
    }
    

    But yours is a bit nicer, I admit.

  • answered 2018-01-13 17:31 mkobit

    As an addition to the other answers, in #kotlin-dsl/256 shortcut methods were added to the various repository methods to do something like the following:

    repositories {
      mavenCentral()
      maven(url = "<MAVEN REPO URL>")
    }
    

    According to the issue, this was added in the Kotlin DSL version 0.11.1. The 0.11.x versions were included in the Gradle 4.2 release.

    To see the Gradle version you are running with your build when using the Gradle wrapper run ./gradlew --version.