创建私有maven仓库

 

Android 搭建私有maven仓库及上传项目

Nexus 介绍
Sonatype Nexus 是一个常见的搭建本地私有仓库的工具,详情进入官网查看https://www.sonatype.com/download-oss-sonatype

搭建私有Nexus仓库
下载 Nexus 安装包
https://www.sonatype.com/download-oss-sonatype

解压 Nexus 文件


## 启动 Nexus 服务

cd nexus-3.30.0-01/bin/

nexus start
1

➜  ~ /Users/xxxx/Downloads/nexus-3.30.0-01-mac/nexus-3.30.0-01/bin
➜  bin nexus start
Starting nexus
➜  bin

到此 Nexus 服务已经启动,访问 http://localhost:8081 即可访问 Nexus 私服,查看本地下载包内容 xxx.password 

初始账户:admin 
初始密码:admin123


Android Lib 发布私有仓库

1、根目录下配置build.gradle

maven {
            url 'http://localhost:8081/repository/maven-public/'
            credentials {
                username = 'admin'
                password = 'admin123'
            }
        }

 


2、在项目根目录下 gradle.properties 中添加配置:

仓库地址如下:

RELEASE_REPOSITORY_URL=http://localhost:8081/repository/maven-releases/
SNAPSHOT_REPOSITORY_URL=http://localhost:8081/repository/maven-snapshots/
GROUP_ID=com.example.test
ARTIFACT_ID=tesLib
USERNAME=admin
PASSWORD=admin123
VERSION=3.0.14-snapshots
Pandroid.debug.obsoleteApi=true
SHORT_VERSION=0

3、在项目根目录下添加gradle 的task 文件 upload.gradle 中添加配置:

apply plugin: 'maven'

uploadArchives {
    repositories {
        mavenDeployer {
            String vsion = project.SHORT_VERSION

            System.out.println("======version:" + vsion)
            pom.project {
                groupId project.GROUP_ID
                artifactId ARTIFACT_ID
                version vsion
            }
            def rootProject = project.rootProject
            pom.withXml {
                it.asNode().dependencies.dependency.findAll {
                    it.groupId.text() == rootProject.name
                }.each {
                    it.groupId.each {
                        it.value = rootProject.GROUP_ID
                    }
                    it.version.each {
                        it.value = vsion
                    }
                }
            }

            repository(url: project.RELEASE_REPOSITORY_URL) {
                authentication(userName: project.USERNAME, password: project.PASSWORD)
            }
        }
    }
}

// 打包并上传源码
task generateSourcesJar(type: Jar) {
    group = 'jar'
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

artifacts {
    archives generateSourcesJar
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值