Installation and use of Gradle

Keywords: Java Maven Gradle nexus Windows

Official website: Gradle installation tutorial portal

I. installation

The installation process of windows and linux is basically the same

1 download the binary Gradle package

2 decompress the package

3 configure the following environment variables according to the compressed package path:

  • Gradle home configures the installation directory of gradle into the environment variable
  • Configure% grade_home% \ bin to the PATH variable
  • (optional) configure the gradle ﹣ user ﹣ home variable to specify the directory for user configuration and cache storage. If not configured, the default is the current user directory \. Gradle

4 run the following command to verify the installation is successful

gradle -v

II. Some practical configurations

1 set up remote download warehouse

Global settings:

In the. Gradle folder under the user directory, create or modify the init.gradle configuration file, and add the following:

allprojects {
    repositories {
        def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
        def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
                    remove repo
                }
                if (url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
                    remove repo
                }
            }
        }
        maven {
            url ALIYUN_REPOSITORY_URL
            url ALIYUN_JCENTER_URL
        }
    }
}

Individual project settings:

In the build.gradle file of the project, add the following:

buildscript {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
                maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }       
}

// Configure the works under the project
allprojects {
    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
        maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
}

Posted by richcrack on Mon, 18 Nov 2019 06:36:12 -0800