JCenter 部署
1、Bintray 个人账号注册
注册个人账号才能免费,并且可以部署到JCenter
2、Add New Repository
- Name 字段填写 maven
- Type 字段选择 Maven
- Default Licenses 字段选择 Apache 2.0
3、Add New Package
- Name 字段填入子仓库名,例如:network
- Version control 字段填入 Github 仓库地址
4、配置 Gradle
- 新建工程以及 Android Library
- root build.gradle 引入:
classpath 'com.novoda:bintray-release:0.8.1'
- library build.gradle 引入:
apply plugin: 'com.novoda.bintray-release'
lintOptions {
abortOnError false
}
if (!isBuildLibraryUI) {
//生成源文件
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
//生成Javadoc文档
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
//文档打包成jar
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
//拷贝javadoc文件
task copyDoc(type: Copy) {
from "${buildDir}/docs/"
into "docs"
}
//上传到JCenter所需要的源码文件
artifacts {
archives javadocJar
archives sourcesJar
}
//解决 JavaDoc 中文注释生成失败的问题
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption('charSet', 'UTF-8')
excludes = ['**/*.kt']
}
// tasks.withType(Javadoc).all {
// enabled = false
// }
//发布到 Bintray
publish {
userOrg = 'username' //用户名,小写
groupId = 'com.readboy.baselibrary' // 依赖仓库名,自定义
artifactId = 'ui' //bintray.com 创建的 Package 名
publishVersion = '1.0.0' //版本号
desc = 'UI 基础库初始化' //版本说明,随意
website = 'https://github.com/L1uj1awe1/BaseLibrary.git' //关于这个开源项目的网站,随意
}
// 依赖效果
// implementation 'com.readboy.baselibrary:ui:1.0.0'
}
5、上传代码
./gradlew clean build generatePomFileForReleasePublication bintrayUpload -PbintrayUser=YourUserName -PbintrayKey=YourApiKey -PdryRun=false