75040806
Local repository Configuration
Configure the environment variable gradle_user_home and point to a local directory to save the dependency package downloaded by gradle.
Remote repository Configuration
Generally, gradle and Maven use mavencentral () Repository from the central repository.
Therefore, in each gradle build project, we can make the following configuration in build. gradle:
Repositories {
Maven {
URL 'HTTP: // maven.aliyun.com/nexus/content/groups/public /'
}
Mavencentral ()
}
It is difficult to configure each project so that 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
}
}
}
Introduction to init. gradle
The init. gradle file is executed before the build starts, so you can configure some operations you want to pre-load in this file.
For example, configure build log output, configure your machine information, such as the JDK installation directory, and configure personal information, such as the authentication information of the repository or database, and so on.
How to enable the init. gradle file:
1. Specify a file in 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. Put the init. gradle file in the user_home/. gradle/directory.
3. Put the file ending with. gradle in the user_home/. gradle/init. d/directory.
4. Put the file ending with. gradle in the gradle_home/init. d/directory.
If two or more of the above four methods exist, gradle will execute these files in sequence according to the numbers 1-4 above. If multiple init scripts exist in the given directory, these scripts are executed in the alphabetical order of A-Z.
Similar to the build. gradle script, the init script is sometimes a groovy language script. Each init script has a corresponding gradle instance. All the methods and attributes you call in this file will
Delegate to this gradle instance. Each init script implements the script interface.
The following example shows how to create a Maven local database for all projects before the build is executed. In this example, the maven repository center is specified in the build. gradle file. 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 in the command line: gradle-init-script init. gradle-Q showrepos
> Gradle -- init-script init. gradle-Q showrepos
All repos:
[Mavenlocal, mavenrepo]
Gradle local and remote repository configuration -- go