Add Maven repository to build.gradle
You will need to define the repository outside of buildscript
. The buildscript
configuration block only sets up the repositories and dependencies for the classpath of your build script but not your application.
How to include maven repository with id in gradle?
This URL is not a fair maven repository (it returns 400: Invalid request after 301: Permanent redirect), so you need to give Gradle a hint, where to look for artifacts metadata - in this case, there is pom.xml in the root :
maven {
url = uri("https://raw.github.com/repeats/SimpleNativeHooks/maven-export/")
metadataSources {
mavenPom()
}
}
How to add an additional Maven repository to Android Studio build
Artic Fox started using another technique built on depedencyResolutionManagment
which introduced this head-scratching situation where the entries in the application-level build.grade
file are not searched.
What worked for me in this situation was to go into settings.gradle
(not build.gradle
and change:
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
to
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
and for good measure, I put my additional repository into settings.gradle
resulting in the following:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) // WAS: FAIL_ON_PROJECT_REPOS
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven {url 'https://mvnrepository.com'} // ADDED THIS
}
}
After making these changes, the appropriate artifacts were automatically downloaded by the Android Studio standard build process.
Adding custom maven dependency to gradle project
You will need to add a local maven repository like this
repositories {
maven { url new File(pathToYourM2Directory).toURI().toURL() }
}
Additionally the declaration of the dependency is not correct. It should be
dependencies {
implementation group: 'com.example.auth.security', name: 'common', version '0.0.1-SNAPSHOT'
}
You can as well fix the files
dependency. However using a local maven repo is more sustainable as by resolving artifacts this way it is transparent for the build process if an artifact is resolved locally or remote.
How to add a Maven project as a Gradle dependency?
You can't really add the Maven multi-module project structure as a dependency directly. You can, however, build the multi-module project using mvn install
to install the project jars to your local repository.
Then, in your build.gradle
, you need the following configuration:
repositories {
mavenLocal()
}
This will add your local Maven repository to the list of code repositories that Gradle will look through for your artifacts. You can then declare a dependency on the module(s) that your Gradle project requires.
dependencies {
compile 'my-group:my-artifact:version',
'my-group:my-other-artifact:version'
}
When the multi-module project updates to a new release version, run mvn install
for that release and update your build.gradle
as needed.
Unless you are the only developer on both projects, it would be better to use a private repository like Nexus or Artifactory to host the maven project and configure Gradle to pull dependencies from there as well.
References:
Maven Local Repository in Gradle: https://docs.gradle.org/2.4/userguide/dependency_management.html#sub:maven_local
Maven Dependencies in Gradle:
https://docs.gradle.org/2.4/userguide/dependency_management.html#sub:module_dependencies
How to add custom maven repository to gradle
You may want to try this:
repositories {
mavenCentral()
maven {
credentials {
username 'admin'
password '*******'
}
url 'https://cloudbuild.livegenic.com/nexus/content/repositories/test_kirill/'
authentication {
basic(BasicAuthentication)
}
}
}
See this discussion for more detail:
https://discuss.gradle.org/t/maven-username-password-only-works-when-embedded-in-url-for-some-servers/2542/13
How to add Repository maven in new Android Studio Project setup(2022)?
In the latest Android Studio Bumblebee(2021.1.1) version, if you see it in build.gradle(Project)
the new structure looks like this
build.gradle(Project)
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
In order to use the other libraries like maven
, you have to go to the settings.gradle
and you have to the maven link like below
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven { url 'https://jitpack.io' } // add like this
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' } // add like this
}
}
rootProject.name = "your project name here"
include ':app'
finally add the library in to your
Build.gradle(module)
dependencies {
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
Gradle is not searching for packages in local Maven repository. How to fix?
The buildscript
clause is only used for resolving plugins (and their depedencies). Add another repositories
clause outside the buildscript
like so:
buildscript {
repositories {
mavenLocal()
...
}
...
}
repositories {
mavenLocal()
...
}
Related Topics
How to Integrate Opencv 4.0 into a Pure C++ Android Ndk Project
Android Studio on a Hardware That Does Not Support Virtualization Technology
Borders on Certain Zoom Levels on Webpage
Cordova "Hello World" App Won't Display
Enable C++11 Support on Android
Android Studio: Exclude Resource File Under Resources Sourcesets
How to Create Ripple Effect in Simple Layout
Signing an APK with an Upload Key Provided by Google Play
How to Filter Listview Using Getfilter() in Baseadapter
How to Read the Sd Card Id Number
Android M Write to Sd Card - Permission Denied
How to Add Firebase Database Rules Without Authentication
Eclipse Can't Find Android.Support.V4.Widget.Swiperefreshlayout
How to Use Std::Stoul and Std::Stoull in Android
Fcm Remote Notifications Payload for iOS and Android
Onpagefinished() Never Called (Webview)!
Android Studio Run/Debug Configuration Error: Module Not Specified