Change Gradle mavenCenter URL of my repo

While working with Gradle in my country, loading cans from maven central is a very timely job.
I want to change mavenCentral to maven-nexus:
this means that whenever I use mavenCentral, it always points to oschina

------ edit ------
I have many projects with mavenCentral, so I do not want to change every file.

Now in new scripts I use maven {url ...} Any easy way?

Can anyone find one? Thanks!

+5
source share
4 answers

The easiest way to apply this change for all projects is to use the gradle init script, which forces you to use the oschina repository instead of mavenCentral. you can put this:

allprojects{ repositories { all { ArtifactRepository repo -> println repo.url.toString() if ((repo instanceof MavenArtifactRepository) && repo.url.toString().startsWith("https://repo1.maven.org/maven2")) { project.logger.warn "Repository ${repo.url} removed. Only $coporateRepoUrl is allowed" remove repo } } maven { url "http://maven.oschina.net/content/groups/public" } } } 

to the gradle initialization file. Now you can use this by calling "gradle build -I yourInitFile.gradle", or you put this logic in the init.gradle file stored in your gradle home directory in the USER_HOME/.gradle/ . Now this will be called by every gradle call without explicitly setting -I

Another option is to create a custom gradle distribution where this file is stored in the init.d directory of the distribution.

+11
source

Easy! Instead of this:

 repositories { mavenCentral() } 

Use this:

 repositories { maven { url "https://..." } } 
+5
source

Just configure the repository in the build.gradle file in the directory of your module, for example:

 repositories { maven { url "http://maven.oschina.net/content/groups/public" } } 
+3
source

If you have a lot of dependencies (i.e. in all build.gradle files) and for the repository urls you use

 repositories { maven { url "https://www.myrepourl.com" } } 

but you want to change this URL in only one file, follow these steps:

  • Create a gradle.properties file and add this line: REPO_URL= https://www.myrepourl.com
  • In all other build.gradle files build.gradle copy the following:

     repositories { maven { url project.REPO_URL } } 

You can add and use more properties this way. It worked like a charm for me. Hurrah!

0
source

Source: https://habr.com/ru/post/1207376/


All Articles