jcenter 开源笔记
一、注册
注意注册区别 组织用户注册:Sign Up to a Free Trial 个人用户注册:Sign Up to an Open Source account
简单粗暴:gmail注册
二、配置
1、项目根目录build.gradle 添加依赖 jcenter-插件依赖和maven插件依赖
旧版maven插件github上显示过期,使用新版本maven插件 每次执行下载都比较麻烦,国内有墙。网速不行就直接下载放到本地,改下连接为本地地址即可
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
}
2、创建maven仓库
- 1、创建repository 填写仓库信息
- 2、创建package 填写包信息
官网新建的package有个设置按钮,点开有各种配置教程,按照对应的example配置,注意把drayRun 设置成false,否则不会真正上传
3、上传模块publish.gradle添加配置 example
apply plugin: 'com.jfrog.bintray'
apply from: 'publish/gradle-mavenizer.gradle'
def String getLocalProperty(String key) {
Properties properties = new Properties()
rootProject.file("local.properties").withInputStream { properties.load(it) }
return properties.getProperty(key)
}
ext {
publish_group_id = "com.shuisechanggong"
publish_artifactId = "base"
publish_version = android.defaultConfig.versionName
publish_package_desc = "base $publish_version"
publish_vcsTag = "1.0.0"
publish_repo = "com.shuisechanggong"
publish_package = publish_artifactId
publish_licenses = ['Apache-2.0']
publish_vcs_url = "git@github.com:OoadaioO/ktdemo.git"
publish_user = getLocalProperty("bintrayUser")
publish_api_Key = getLocalProperty("bintrayApiKey")
publish_description = "shuisechanggong base android lib"
}
version = publish_version
group = publish_group_id
project.ext{
mavDevelopers = ["bo":"bworkid"]
mavSiteUrl = "https://github.com/OoadaioO/ktdemo"
mavGitUrl = mavSiteUrl + '.git'
mavProjectName = 'base'
mavPublishToInternalRepo = true
mavRepoInternalUrl = "${project.buildDir}/repo"
mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
mavLibraryDescription = "$publish_description"
}
bintray {
user = publish_user
key = publish_api_Key
configurations = ['archives']
pkg {
repo = publish_repo
name = publish_package
description = publish_description
licenses = publish_licenses
vcsUrl = publish_vcs_url
publish = true // 上传,并发布
publicDownloadNumbers = true
dryRun = true // true-本地执行,不上传,false-执行上传
version {
name = publish_version
desc = publish_package_desc
released = new Date()
vcsTag = publish_vcsTag
}
}
publications = ['mavenPublish'] // 本地maven配置
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
注意:
- 这里bintrayUser和bintrayApiKey 放在local.properties中,忽略上传,避免暴露信息
- bintray下的publications属性必须填写,不然不会上传pom,导致无法添加到jcenter
- jcenter没有添加通过,可以用添加仓库路径访问
repositories {
maven { url "https://dl.bintray.com/bworkid/com.shuisechanggong" }
google()
jcenter()
}
allprojects {
repositories {
maven { url "https://dl.bintray.com/bworkid/com.shuisechanggong" }
google()
jcenter()
}
}
4、 add to jcenter
jcenter控制中心-》仓库管理-》package管理-》右侧有个actions按钮-》添加到jcenter 发送邮件,不要勾选选项