AS 上传 Moudle 到 到 JCenter 仓库

方法一:

1. 加载从远程仓库的架包

在这里插入图片描述
说明:在工程文件的 build.gradle
两个架包

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

2. bintray 的【用户名】和【私钥】

在这里插入图片描述
说明:
注册远程仓库 地址
在这里插入图片描述

3. 复制文件

//========================jcenter 仓库============================
//apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.jfrog.bintray'
//def siteUrl ='https://github.com/hongyelinggu/TimeOut'
//
项目的主页 这个是说明,可随便填
//def gitUrl = 'https://github.com/hongyelinggu/TimeOut'
Git 仓库的 url 这个是说明,可随便填
//group = "com.chaoqianhong.TimeOut"
 这里是 groupId ,必须填写 一般填你唯一的包名
//def repoName = "Android-ProjectTools"
//def libName = "TimeOut"
 版本号,下次更新是只需要更改版本号即可
//version = "1.0.0"
//install {
//    repositories.mavenInstaller {
 This generates POM.xml with proper parameters
//        pom {
//            project {
//                packaging 'aar'
 Add your description here
//                name = libName //发布到 JCenter 上的项目名字,必须填写
//                url siteUrl
 Set your license
//                licenses {
//                    license {
//                        name 'The CommonUtil Software License, Version1.0.0'
//                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
//                    }
//                }
//                scm {
//                    connection gitUrl
//                    developerConnection gitUrl
//                    url siteUrl
//                }
//            }
//        }
//    }
//}
//task sourcesJar(type: Jar) {
//    from android.sourceSets.main.java.srcDirs
//    classifier = 'sources'
//}
//
//artifacts {
//    archives sourcesJar
//}
//Properties properties = new Properties()
//properties.load(project.file('../local.properties').newDataInputStream())
//bintray {
//    user = properties.getProperty("bintray.user")
//    //读取local.properties 文件里面的 bintray.user
//    key = properties.getProperty("bintray.apikey")
//    //读取local.properties 文件里面的 bintray.apikey
//    configurations = ['archives']
//    pkg {
//        repo = repoName
//        name = libName
//        //发布到 JCenter 上的项目名字,必须填写,对应 com.squareup.okhttp3:okhttp:3.4.1 中的 okhttp
//        websiteUrl = siteUrl
//        vcsUrl = gitUrl
//        licenses = ["Apache-2.0"]
//        publish = true
//    }
//}

4. 运行

在这里插入图片描述

  1. 生成 maven 库所需要的 POM 文件:graedlew install
  2. 上传你的 Library 库到 jcenter 的 maven 库:graedlew bintrayUpload

方法二:

转至博客 果冻豆人

Bintray/JCenter/JitPack发布及配置流程

前言

本文目的是希望把项目模块化、组件化,提供上传,方便依赖。

Bintray

官网: bintray.com/

账号注册与登录等步骤直接忽略,登录后点击图中按钮,添加仓库。
插图

填写完成后,点击Create创建仓库。这里的Type为仓库类型,例如Maven、Docker、Npm等等。协议一般为Apache2.0。
插图

仓库创建完成后,点击Add New Package,添加依赖包。
插图

填写完成功后,点击Create Package,创建依赖包。依赖包名称就是上传时候填写的artifactId。
插图

在此,网上找了很多资料后,最终决定使用bintray插件novoda来上传发布,可以极大的简化bintray发布流程。

在模块的build.gradle下,添加如下

// 当模块必须声明为com.android.library时才能使用,否则会报错
apply plugin: 'com.novoda.bintray-release'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.novoda:bintray-release:0.8.0'
    }
}

publish {
    repoName = 'android'  // 此字段为你的仓库名称,默认为"maven",上传的时候记得检查,否则上传会报错
    userOrg = 'novoda'  // bintray用户名
    groupId = 'com.novoda'  // 模块目录
    artifactId = 'bintray-release'  // 此字段为你的模块名称,唯一标识符
    publishVersion = '0.6.1'  // 版本号
    desc = 'Oh hi, this is a nice description for a project, right?'
    website = 'https://github.com/novoda/bintray-release'
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

如需其他字段,可以查阅Wiki

最终,执行上传发布命令。BINTRAY_USERNAME为你的bintray的用户名,BINTRAY_KEY为你的bintray的apikey。

gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
 
 
  • 1

查看apikey方法如下
插图

JCenter

这个比较简单,bintray发布完成后,点击”Add To JCenter”,填写开源说明,点击Send就好了。但需要审核(大概一天)通过后才能依赖使用。
插图
插图

JitPack

官网:jitpack.io

Bintray配置虽然不麻烦,但也不简单。如果想更简单更轻松的发布的话,可以用JitPack。几乎可以算是一步搞定!

进入官网,并用github账号登录,他会直接关联到你github里的项目,然后选择需要发布的项目,选择版本Version,点击Get it!然后?就没然后了…这样就好了,可以在项目里依赖了。
Version名称可以用git添加tag来改变。
插件

在你项目的build.gradle里,添加仓库”https://jitpack.io“.

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

然后在模块里添加依赖.

dependencies {
    compile 'com.github.xhjnono:android-exercises:-SNAPSHOT'
}
 
 
  • 1
  • 2
  • 3

至此完成发布。

总结

JitPack虽然是最简单的,但是他是基于把整个项目作为依赖的,Bintray/JCenter则可以上传单个模块作为依赖,所以还是根据个人所需来选择吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值