Multiple maven repositories in one gradle file - maven

So my problem is how to add multiple maven repositories to one gradle file.
This DOESN’T work:
repositories {
mavenCentral()
maven {
url "http://maven.springframework.org/release"
url "http://maven.restlet.org"
}
}

you have to do like this in your project level gradle file
allprojects {
repositories {
jcenter()
maven { url "http://dl.appnext.com/" }
maven { url "https://maven.google.com" }
}
}

Related

Gradle: Could not resolve com.squareup.okhttp3:okhttp:3.12.+

Since today, and I didn't change anything in my Gradle files, there is an error during the building:
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.squareup.okhttp3:okhttp:3.12.+.
For information in my Gradle:
allprojects {
repositories {
google()
mavenCentral()
// jcenter()
maven { url = "https://jcenter.bintray.com" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
maven { url "https://dl.cloudsmith.io/public/cometchat/cometchat-pro-android/maven/" }
flatDir {
dirs 'src/main/libs'
}
}
}
According to gradle status, jcenter has some issues still.

What is the correct way of changing jcenter to mavenCentral?

I am working on an old project and Android Studio recommended me to update to mavenCentral().
I had this code:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.google.gms:google-services:4.3.13
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And I have changed it to this one:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.1'
classpath 'com.google.gms:google-services:4.3.13
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now my question is, is it enough just changing jcenter() for mavenCentral() to update from jcenter to mavenCentral like I have done or should I make something else to update from jcenter to mavenCentral?
Yeah, it should be enough just changing jcenter() to mavenCentral() if your project is building successfully.
If not then you need to check what missing library in mavenCentral is failing your build. Then learn which ways you have to fix it, for some libs you will need to use jitpack, for others upgrade to a version (where the author migrated it to mavenCentral), or host it locally in the project, etc.
Also, don't forget to do it for build.gradle in your other modules (not only root).

Could not find com.github.searchy2:CustomButton:1.9.0. ERROR

My build.gradle file looks like this:
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
maven { url 'https://jitpack.io' }
maven { url 'https://maven.google.com' }
maven { url 'https://plugins.gradle.org/m2/' }
jcenter() // Warning: this repository is going to shut down soon
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath 'com.google.gms:google-services:4.3.10'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ERROR
Could not find com.github.searchy2:CustomButton:1.9.0.
Required by:
project :app > com.github.searchy2:CustomPermissionsDialogue:2.2.1

Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0

I have created the account and key needed from Mapbox. I have listed the repositories in different order with no luck. Whn building, the following error appears:
Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom
- https://repo.maven.apache.org/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom
Required by:
project :app > com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1
Here's my build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.20"
repositories {
google()
mavenCentral()
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
// Do not change the username below.
// This should always be `mapbox` (not your username).
username = 'mapbox'
// Use the secret token you stored in gradle.properties
password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
}
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've added the following to my module level build.gradle
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.2.1'
I have only added jcenter() and it works. However, jcenter() is deprecated.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
It seem like they remove mapbox-android-accounts repository.
Check this: https://mvnrepository.com/artifact/com.mapbox.mapboxsdk/mapbox-android-accounts/0.8.0
Github page is empty.
Works for me after jcenter() added.
I added jcenter() to buildscript -> repositories and allprojects -> repositories:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
maven {
url 'https://api.mapbox.com/downloads/v2/releases/maven'
authentication {
basic(BasicAuthentication)
}
credentials {
username "mapbox"
password "YOUR_TOKEN"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}

gradle overwrite plugin repository from init script

How can I overwrite all plugin repositories in gradle via the init script?
allprojects {
repositories {
maven { url "foo" }
}
}
only works for regular repositories - not for plugin repositories.
Plugins are registerd via the old buildscript{ repositories { }} notation
simply adding:
allprojects {
buildscript{
repositories{
maven { url "https://foo.com" }
}
}
repositories {
maven { url "https://foo.com" }
}
}
is the solution

Resources