2022年8月

Gradle 添加私有仓库

以Android Studio为例

  1. build.gradle(Project)中添加maven{...},如下所示:

    buildscript {
        repositories {
            maven {
                url "https://maven.imcaoxuan.cn:8443/repository/public/"
                credentials {
                    username = 'public'
                    password = 'public'
                }
            }
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:7.0.4'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
  2. settings.gradle(Project)中添加maven{...},如下所示:

    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            maven {
                url "https://maven.imcaoxuan.cn:8443/repository/public/"
                credentials {
                    username = 'public'
                    password = 'public'
                }
            }
            google()
            mavenCentral()
            jcenter() // Warning: this repository is going to shut down soon
        }
    }

    3.Sync now!