Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>'   } } 
like image 687
Florian Reisinger Avatar asked Jan 13 '18 17:01

Florian Reisinger


People also ask

Does gradle use Maven repository?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.

What is DSL in gradle?

Simply, it stands for 'Domain Specific Language'. IMO, in gradle context, DSL gives you a gradle specific way to form your build scripts. More precisely, it's a plugin-based build system that defines a way of setting up your build script using (mainly) building blocks defined in various plugins.

What is Gradle repository in Maven?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.

How do I add a Maven repository to my project?

You have to add repositories to your build file. For maven repositories you have to prefix repository name with maven {} Add the maven repository outside the buildscript configuration block of your main build.gradle file as follows: Thanks for contributing an answer to Stack Overflow!

What is maven central repository in Android Studio?

Maven Central is a popular repository hosting open source libraries for consumption by Java projects. To declare the Maven Central repository for your build add this to your script: Example 1. Adding central Maven repository The Google repository hosts Android-specific artifacts including the Android SDK.

What are some examples of public repositories in Gradle?

Popular public repositories include Maven Central and the Google Android repository. Gradle provides built-in shorthand notations for these widely-used repositories. Figure 1. Declaring a repository with the help of shorthand notations


2 Answers

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.

like image 195
mkobit Avatar answered Sep 19 '22 06:09

mkobit


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

repositories {     mavenCentral()     maven {         setUrl("<MAVEN REPO URL>")     } } 
like image 28
Florian Reisinger Avatar answered Sep 20 '22 06:09

Florian Reisinger