This article introduces the method of Gradle using Maven repository. I will share it with you. The details are as follows:
In the build.gradle file, modify repositories as follows:
repositories { mavenLocal() mavenCentral() }In this way, you will prioritize finding the required jar package from maven's repository
My maven configuration local repository is in D:/repository (see "How to modify maven local repository address" at the bottom). To prevent downloading to the default directory of the C drive, it is recommended to copy setting.xml to the C:/Users/username/.m2/ directory.
When the dependency jar package in build.gradle has been downloaded through maven, it will not be downloaded repeatedly. However, if it has not been downloaded, gradle will download it to the configuration path, as shown in the figure below
I feel that it would be even better if the gradle repository can be downloaded to the maven repository after gradle.
How to modify the local repository address of maven
Go to the maven directory (such as: ../apache-maven-3.3.9/conf/settings.xml), modify the settings.xml file, the content is as follows:
<localRepository>D:/repository/</localRepository>
How to use domestic mirrors
If using maven
Find settings.xml and set the source. Here we use Alibaba Cloud's source, and the speed is still quite fast.
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf></mirror>
If using gradle
Create a new file init.gradle under USER_HOME/.gradle/, enter the content below and save.
allprojects{ repositories { def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/' all { ArtifactRepository repo -> if(repo instanceof MavenArtifactRepository){ def url = repo.url.toString() if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) { project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL." remove repo } } } maven { url REPOSITORY_URL } }}The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.