android-搭建本地maven仓库

还在烦恼 Android Studio 打包要 翻, 墙 有木有?

或者配上国内 阿里云 的源.

不如直接内网搭建一个 Maven 仓库, 断网都不怕的有木有!!!


前篇


启动 nexus 服务

  • 启动, 用管理员权限运行命令

    1
    2
    3
    4
    5
    6
    $ nexus.exe /run
    -------------------------------------------------

    Started Sonatype Nexus OSS 3.25.0-03

    -------------------------------------------------

    启动成功就可以访问: http://localhost:8081/

    默认用户名 admin,密码 不再是 admin123, 而是在 sonatype-work/nexus3/admin.password 中, 首次登陆修改完后会自动删除.

  • 修改端口号

    修改文件 nexus-3.25.0-03\etc\nexus-default.properties

    1
    application-port=8081

Repository 的 type 属性

Repository 的 type 属性有:proxy,hosted,group三种

  • proxy:即你可以设置代理,设置了代理之后,在你的nexus中找不到的依赖就会去配置的代理的地址中找
  • hosted:你可以上传你自己的项目到这里面
  • group:它可以包含前面两个,是一个聚合体。一般用来给客户一个访问nexus的统一地址

1. 新增代理仓库

  1. 新建一个类型为 proxy 的仓库, 名为 rummy

    配置远程地址为: http://maven.aliyun.com/nexus/content/groups/public

    可以获取到这个仓库的地址: http://192.168.1.233:8081/repository/rummy/


2. Android Studio 配置仓库

在 项目级 build.gradle 中配置地址

1
2
3
4
5
6
7
8
9
10
11
12
13
allprojects {
repositories {
maven {
credentials { // 认证
username 'admin'
password 'asdasd'
}
url 'http://192.168.1.233:8081/repository/rummy/'
}
google()
jcenter()
}
}

然后构建一下, 就会把库缓存到 rummy 中.


3. 查看缓存库


unity 中修改 Maven 仓库

修改 unity 中的 Plugins/Android/mainTemplate.gradle 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
buildscript {
repositories {
// 外网 Maven
// mavenCentral()
// google()
// jcenter()

// 修改为 内网 Maven
maven { url 'http://192.168.1.233:8081/repository/rummy_maven_central/' }
maven { url 'http://192.168.1.233:8081/repository/rummy_google/' }
maven { url 'http://192.168.1.233:8081/repository/rummy_jcenter/' }
}

dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.3'
**BUILD_SCRIPT_DEPS**}
}

allprojects {
repositories {
// 外网 Maven
// mavenCentral()
// google()
// jcenter()

// 修改为 内网 Maven
maven { url 'http://192.168.1.233:8081/repository/rummy_maven_central/' }
maven { url 'http://192.168.1.233:8081/repository/rummy_google/' }
maven { url 'http://192.168.1.233:8081/repository/rummy_jcenter/' }

flatDir {
dirs 'libs'
}
}
}

相关 maven 仓库镜像


阿里云

阿里云云效 是企业级一站式 DevOps 平台,覆盖产品从需求到运营的研发全生命周期,其中云效也提供了免费、可靠的Maven私有仓库 Packages,欢迎您体验使用。

仓库名称 阿里云仓库地址 阿里云仓库地址(老版) 源地址
central https://maven.aliyun.com/repository/central https://maven.aliyun.com/nexus/content/repositories/central https://repo1.maven.org/maven2/
jcenter https://maven.aliyun.com/repository/public https://maven.aliyun.com/nexus/content/repositories/jcenter http://jcenter.bintray.com/
public https://maven.aliyun.com/repository/public https://maven.aliyun.com/nexus/content/groups/public central仓和jcenter仓的聚合仓
google https://maven.aliyun.com/repository/google https://maven.aliyun.com/nexus/content/repositories/google https://maven.google.com/
gradle-plugin https://maven.aliyun.com/repository/gradle-plugin https://maven.aliyun.com/nexus/content/repositories/gradle-plugin https://plugins.gradle.org/m2/
spring https://maven.aliyun.com/repository/spring https://maven.aliyun.com/nexus/content/repositories/spring http://repo.spring.io/libs-milestone/
spring-plugin https://maven.aliyun.com/repository/spring-plugin https://maven.aliyun.com/nexus/content/repositories/spring-plugin http://repo.spring.io/plugins-release/
grails-core https://maven.aliyun.com/repository/grails-core https://maven.aliyun.com/nexus/content/repositories/grails-core https://repo.grails.org/grails/core
apache snapshots https://maven.aliyun.com/repository/apache-snapshots https://maven.aliyun.com/nexus/content/repositories/apache-snapshots https://repository.apache.org/snapshots/