Gradle local and remote warehouse configuration – transfer

https://blog.csdn.net/x_iya/article/details/75040806

Local warehouse configuration environment variable grade_ USER_ Home and point to your local directory to save the dependent packages downloaded by gradle.

The remote warehouse is generally configured with gradle and Maven from the central warehouse (Maven central) http://repo1.maven.org/maven2/ Download depends on the package, but the download speed in China is very slow. We can only use the domestic image. So in every project built by gradle, we can build The gradle is configured as follows

repositories { maven { url ' http://maven.aliyun.com/nexus/content/groups/public/ '} maven central()} each project is configured like this. It's hard to avoid trouble. We can configure a global configuration file.

. gradle\init. gradle

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 } }}

init. Introducing gradle init The gradle file is executed before the start of build, so you can configure some operations you want to preload in this file, such as configuring build log output, configuring your machine information, such as JDK installation directory, configuring personal information, such as warehouse or database authentication information, and so on

Enable init Methods of gradle file: 1. Specify the file on the command line, for example: gradle – init script yourdir / init gradle -q taskName. You can enter this command multiple times to specify multiple init files. 2 Place gradle file in user_ HOME/. Gradle / directory 3. Take it Put the file at the end of gradle in user_ HOME/. gradle/init. D / directory 4. Take it Put the file at the end of gradle into gradle_ HOME/init. D / directory

If there are more than two of the above four methods, gradle will execute these files in the order of 1-4 above. If there are multiple init scripts in a given directory, these scripts will be executed in pinyin A-Z order, similar to build Gradle scripts, init scripts, and sometimes groovy language scripts. Each init script has a corresponding gradle instance. All the methods and attributes you invoke in this file are delegated to the gradle instance. Each init script implements the Script interface.

The following example is to make Maven local library for all projects before the execution of build. This example is also in build. Com The gradle file specifies the warehouse center of Maven. Note the similarities and differences between them

build. gradle

repositories { mavenCentral()}

task showRepos << { println "All repos:" println repositories.collect { it.name }}init. gradle

Allprojects {repositories {mavenlocal() enter the command on the command line: gradle – init script init.gradle - Q showrepos

> gradle --init-script init. gradle -q showReposAll repos:[MavenLocal,MavenRepo]

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>