Android maven 仓库配置优化

Android maven 仓库配置优化

  • 第三方仓库,一般只需要指定的 group 的库,此时可以使用:
maven {
    url 'https://xxx.com'
    content {
        includeGroupByRegex 'com.company.*'
    }
}
  • 指定仓库仅包含指定的 group 相关库, 来减少频繁的仓库拉取操作。
    支持方法:
includeGroup
includeModule
includeVersion
excludeGroup
...

参考:https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/repositories/RepositoryContentDescriptor.html

唯一排他的仓库

有时候,有且仅有指定仓库,才包含 库。这样指定lib,只需要到指定的maven中拉取。
不需要再去逐个获取失败,知道获取成功的方式。

repositories {
    // This repository will _not_ be searched for artifacts in my.company
    // despite being declared first
    mavenCentral()
    exclusiveContent {
        forRepository {
            maven {
                url "https://repo.mycompany.com/maven2"
            }
        }
        filter {
            // this repository *only* contains artifacts with group "my.company"
            includeGroup "my.company"
        }
    }
}

这个代码表明,有且仅有这个仓库才包含 my.company group 的lib,遇到 my.company 就直接拉取这个仓库。

参考:https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/repositories/InclusiveRepositoryContentDescriptor.html

过滤snapshots和releases

repositories {
    maven {
        url "https://repo.mycompany.com/releases"
        mavenContent {
            releasesOnly()
        }
    }
    maven {
        url "https://repo.mycompany.com/snapshots"
        mavenContent {
            snapshotsOnly()
        }
    }
}

中国配置aliyun的仓库镜像替代官方

Android现在默认使用 google、mavenCentral 两个,由于各种原因访问速度或不通。

使用阿里替代

repositories {
    //gradlePluginPortal()
    //google()
    //mavenCentral()

    maven { url 'https://maven.aliyun.com/repository/google' }
    //central和jcenter的聚合仓库
    maven { url 'https://maven.aliyun.com/repository/public' }
    //仅顶级build.gradle需配置插件仓库
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}

阿里云云效Maven: https://developer.aliyun.com/mvn/guide

gradle仓库配置文档

https://docs.gradle.org/current/userguide/declaring_repositories.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值