写在前面:
之前尝试上传aar到github 然后本地引用一直不成功 也不知道咋整的 所以尝试了下 上传到maven 挺好用 顺便记录下
1.注册账号
https://bintray.com/ 如下图 建议选择自己注册 不使用三方登录 (可能会有坑)
登录之后 点击编辑
之后来获取我们的apikey 输入密码 提交之后 就能看到
获取apikey 之后 通过show可以查看 然后暂时先不管它
之后创建仓库(点击Responsetories)
下面填写的 和gradle 中的配置有关 如果不想采坑 可以和我的一模一样
此时 仓库搞定 那么接下来 我们创建属于自己的项目 在里面创建一个叫lesscode-cord的library
再project的 build.gradle 添加依赖
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
再library库的build.gradle 的根节点下添加
version = "0.1" // 根节点添加 def siteUrl = 'https://github.com/zhangyanjiao/myRepository1' // project homepage def gitUrl = 'https://github.com/zhangyanjiao/myRepository1.git' // project git group = "com.zyj.repos"//任意名称都可以 // 根节点添加 install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' name 'Less Code For Android' url siteUrl licenses { license { name 'The Apache Software License, Version 2.0'//刚才创建仓库时的许可证 url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'yanjiao' name 'yanjiao.zhang' email '[email protected]' } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' } task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } task javadocJar(type: Jar, dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir } artifacts { archives javadocJar archives sourcesJar } Properties properties = new Properties() boolean isHasFile = false if (project.rootProject.file('loca') != null){ isHasFile = true properties.load(project.rootProject.file('local.properties').newDataInputStream()) } bintray { user = isHasFile ? properties.getProperty("bintray.user") : System.getenv("bintray.user") key = isHasFile ? properties.getProperty("bintray.apikey") : System.getenv("bintray.apikey") configurations = ['archives'] pkg { repo = "maven"//仓库名称 name = "lesscode"//项目名称 // #CONFIG# project name in jcenter websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }
然后再local.properties 中 配置用户名和apikey(刚刚申请的那个) 别忘了上传的时候忽略改文件 要不信息就泄漏了
bintray.user=zhangsan
bintray.apikey=5ab75d133c2bd1c619e455156252556
添加完成之后 最后 执行gradle 上传 命令 最简单的方式