AndroidStudio发布公共类库到Maven仓库(Nexus)

一、 打包并发布项目
1. 编写gradle脚本

在需要发布为公共类库的module的build.gradle文件引入maven插件:

在此gradle文件根部添加发布代码:
apply plugin: 'maven'

def MAVEN_LOCAL_PATH = 'http://127.0.0.1:8888/repository/android-release/' //服务端ip地址端口及放置的目录
def ARTIFACT_ID = 'checksign'  //artifactId
def VERSION_NAME = '1.0.0' //版本名称
def GROUP_ID = 'com.eaway.corelib'  //groupId
def PROJECT_NAME = 'corelib'
def ACCOUNT = 'admin'
def PASSWORD = 'admin123'

//脚本:将Lib打成aar包上传至maven私有库
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: MAVEN_LOCAL_PATH) {
                authentication(userName: ACCOUNT, password: PASSWORD)
            }
            pom.project {
                name PROJECT_NAME
                groupId GROUP_ID
                artifactId ARTIFACT_ID
                version VERSION_NAME
                packaging 'aar'
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }
            }
        }
    }
}
2. 打包发布
在后台窗口进入所在目录,输入指令gradle uploadArchives(前提是先配置gradle环境变量)

3. 在服务端查看是否已生成并上传成功

二、引用已发布的公共类库
1. 在项目根目录下的build.gradle文件中的allprojects -> repositories中添加maven服务端地址:
allprojects {
       repositories {
           jcenter()
           maven { url "http://127.0.0.1:8888/repository/android-release/" }
       }
   }
2. 在需要引用公共类库的module的build.gradle中的dependencies加入
compile 'groupId:artifactId:version'
dependencies {
       compile fileTree(dir: 'libs', include: ['*.jar'])
       androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
           exclude group: 'com.android.support', module: 'support-annotations'
       })
       compile 'com.android.support:appcompat-v7:23.0.1'
       testCompile 'junit:junit:4.12'
       compile 'com.eaway.corelib:checksign:1.0.0'
   }



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值