设为首页 加入收藏

TOP

将Android封装库通过gradle部署到maven私服并依赖使用
2019-09-14 00:53:02 】 浏览:47
Tags:Android 封装 通过 gradle 部署 maven 私服 依赖 使用

一、在需要发布的模块chrisbaselibrary下的build.gradle中添加以下部分

//maven插件
apply plugin: 'maven'
 
//打包main目录下代码和资源的 task
task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}
//配置需要上传到maven仓库的文件
artifacts {
    archives androidSourcesJar
}
//上传到Maven仓库的task
uploadArchives {
    repositories {
        mavenDeployer {
            //指定maven仓库url 如果使用快照库需要注意版本号的后缀
            repository(url: "http://maven.ai-ways.com/nexus/content/repositories/releases/") {
                //nexus登录默认用户名和密码 userName大小写要匹配
                authentication(userName: "admin", password: "Aa1111111")
            }
            pom.groupId = 'com.chris'
            pom.artifactId = 'base-library'
            pom.version = '1.0.0'
        }
    }
}

直接添加到最后即可。

使用gradle的插件uploadArchives实现部署。

部署成功后,我们可以修改app模块的依赖方式。不过建议另外建一个项目进行依赖测试,毕竟这个项目中的app模块是用来做实时测试的,不需要先部署再同步。

修改project的build.gradle文件中的仓库设置:

allprojects {
    repositories {
        maven {
            url 'http://maven.ai-ways.com/nexus/content/repositories/releases'
        }
        google()
        jcenter()
        
    }
}

然后再在module下的build.gradle中添加依赖:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
 
    //implementation project(path: ':chrisbaselibrary')
    implementation 'com.chris:base-library:1.0.0'
}

 

 



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Android源码阅读技巧--查找开发者.. 下一篇Android-打包AAR步骤以及最为关键..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目