table of Contents
First, create an account and Maven repository Bintray
1, open Bintray home page , click on the Open Source AN the Account the For
, quickly register or login to third-party accounts.
2, personal page, click Add New Repository create a Mavne warehouse
3, fill in the information warehouse, warehouse Name Remember useful later
Second, upload the project to jcenter
1. Configure Android project
Build.gradle add the following code in the root directory of the project:
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
Create a j-build.gradle file in the root directory of the need to upload module project, document reads as follows:
// 这里添加下面两行代码。
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
// 定义两个链接,下面会用到。
def siteUrl = 'https://github.com/881205wzs/UItraPullToRefresh' // 项目主页。
def gitUrl = 'https://github.com/881205wzs/UItraPullToRefresh.git' // Git仓库的url。
// 唯一包名,比如implementation 'com.davis.ui.pulltorefresh:pulltorefresh:2.1.0'中的com.davis.ui.pulltorefresh就是这里配置的。
group = "com.davis.ui.pulltorefresh"
//项目引用的版本号,比如implementation 'com.davis.ui.pulltorefresh:pulltorefresh:2.1.0'中的2.1.0就是这里配置的。
version = "2.1.0"
install {
repositories.mavenInstaller {
// 生成pom.xml和参数
pom {
project {
packaging 'aar'
// 项目描述,复制我的话,这里需要修改。
name 'uitrapulltorefresh'// 可选,项目名称。
description 'UItraPullToRefresh project describe'// 可选,项目描述。
url siteUrl // 项目主页,这里是引用上面定义好。
// 软件开源协议,现在一般都是Apache License2.0吧,复制我的,这里不需要修改。
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
//填写开发者基本信息,复制我的,这里需要修改。
developers {
developer {
id 'wzs' // 开发者的id。
name 'daivs' // 开发者名字。
email '[email protected]' // 开发者邮箱。
}
}
// SCM,复制我的,这里不需要修改。
scm {
connection gitUrl // Git仓库地址。
developerConnection gitUrl // Git仓库地址。
url siteUrl // 项目主页。
}
}
}
}
}
// 生成jar包的task,不需要修改。
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
// 生成jarDoc的task,不需要修改。
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// destinationDir = file("../javadoc/")
failOnError false // 忽略注释语法错误,如果用jdk1.8你的注释写的不规范就编译不过。
}
// 生成javaDoc的jar,不需要修改。
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
// 这里是读取Bintray相关的信息,我们上传项目到github上的时候会把gradle文件传上去,所以不要把帐号密码的信息直接写在这里,写在local.properties中,这里动态读取。
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user") // Bintray的用户名。
key = properties.getProperty("bintray.apikey") // Bintray刚才保存的ApiKey。
configurations = ['archives']
pkg {
repo = "maven" //Repository名字 需要自己在bintray网站上先添加
name = "UItraPullToRefresh"// 发布到Bintray上的项目名字,这里的名字不是implementation 'com.davis.ui.pulltorefresh:pulltorefresh:2.1.0'中的pulltorefresh。
userOrg = 'wzs'//Bintray的组织id
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true // 是否是公开项目。
}
}
注:在最后的bintray里面有从local.properties文件中获取用户名跟apikey。这是保密信息,我们不能暴露给别人,build.gradle文件我们会提交到git服务器上,但是local.properties文件不会提交
。
local.properties file, add two lines at the end, the key is I just modified, is the wrong key, to make their own replacement:
bintray.user=wzs
bintray.apikey=ac8137c9138a8b49a18a323260041fcf1f75a6f
We are a registered user name, apikey jcenter need to go to the official website to view. Enter modify the user interface, click on the left apikey button, then enter the password will be able to see it. Copy this key to the local.properties replaced.
Then we add the following code at the end of build.gradle file module root directory:
apply from: 'j-build.gradle'
Gradle command uploads
Upload projects to jcenter need to use gradle command, first gralde added to the environment variable. How to configure the environment variable is not here in the repeat.
At the bottom of android studio has a Terminal buttons. Click on it to enter Terminal interface.
In turn execute the following command:
gradle clean
gradle install
BUILD SUCCESSFUL appears on that success.
Then enter the command to continue to submit items to bintray:
gradle bintrayUpload
This command will prompt the upload progress, upload it to 100% on the success of last will appear BUILD SUCCESSFUL. At this step you progress bar has reached 90 percent, and he sent last step.
3, quoted in the project
Get your Maven URL and configure build.gradle in the root directory of the project requires the use of.
maven { url 'https://dl.bintray.com/wzs/maven'}
You can add rely on Moudle of build.gradle file references.
implementation 'com.davis.ui.pulltorefresh:pulltorefresh:2.1.0'
In Bintray lib overview can be found maven, gradle, ivy and other configuration reference
now your lib can be used normally, but fortunately their own use, if it is shared with others, everyone needs in their Project of the build.gradle Add maven {url 'https://dl.bintray.com/wzs/maven'}, otherwise they can not download your lib, so it is necessary to synchronize your lib Jcenter library because Jcenter is a standard managed library, almost all will be included in build.gradle jcenter () to access.
3、Add to JCenter
First, under the first upload into your library path, and then click Actions> Add to jcenter add your own lib.
Depending on your situation here lib choice, if not the pom project, you can only select the latter option.
Or by https://bintray.com/beta/#/bintray/jcenter
Can open jcenter warehouse, then click Actions> Include My Package add your own lib.
Send, and then wait for approval of it.