All Products
Search
Document Center

Manage gradle dependencies

Last Updated: Dec 01, 2021

Gradle provides the function of configuring dependency repository and release repository.

Configure a dependency repository

The following shows an example of a common dependency repository of mPaaS:

allprojects {
    repositories {
        mavenLocal()
        flatDir {
            dirs 'libs'
        }
        maven {
            credentials {
                username "*******"
                password "*******"
            }
            url "http://mvn.cloud.alipay.com/nexus/content/repositories/releases/"
        }
        maven{url 'http://maven.aliyun.com/nexus/content/groups/public/'}
        maven{url 'http://maven.aliyun.com/nexus/content/repositories/google'}
    }
}
  • mavenLocal: Maven local repository.

  • flatDir: Dependency under the libs directory of the project.

  • Maven: The example contains the Maven repositories of Ant Financial (mvn.cloud.alipay.com) and Alibaba Cloud (maven.aliyun.com).

You can add dependency repositories under repositories.

Configure a release repository

Gradle provides the function of configuring release repositories. This topic introduces common examples of release repositories to help you modify the path of the local Maven repository ( ~/.m2 by default) and add a custom release repository.

Release repository example

Generally, the build.gradle file contains the following configuration:

uploadArchives {
    repositories {
        mavenLocal()
    }
}

This means that the release repository is Local Maven repository. That is, the .jar package created by the project is automatically released to the local Maven repository.

Modify the local Maven repository path

Local Maven repository (mavenLocal). The default path is~/.m2. You can modify the path.

Customize a release repository

You can add a custom release repository as required. The following shows an example.

uploadArchives {
    mavenDeployer {
        mavenLocal()
        repository(url: "your_repository_url") {
            authentication(userName: '*****', password: '*****')
        }
        snapshotRepository(url: "your_repository_url") {
            authentication(userName: '*****', password: '*****')
        }
    }
}