1.到https://bintray.com/注册一个账号
2.AndroidStudio创建一个项目,然后再在这个项目里创建一个library(File->New->New Module->Android Library)
3.打开项目根目录的gradle.properties文件,复制下面的内容,替换相应字段的值
VERSION_NAME=0.1.0 GROUP=com.zzb.library POM_NAME=jcenter test POM_ARTIFACT_ID=common POM_PACKAGING=aar #比如我们引用appcompat-v7,那么会这么写 compile ‘com.android.support:appcompat-v7:22.2.0‘ #实际对应的字段就是 compile ‘GROUP:POM_ARTIFACT_ID:VERSION_NAME‘ POM_DESCRIPTION=项目描述 #项目地址等,我这使用的是github的项目地址 POM_URL=https://github.com/BaronZ/android-common-library POM_SCM_URL=https://github.com/BaronZ/android-common-library POM_SCM_CONNECTION=scm:git:git://github.com/BaronZ/android-common-library.git POM_SCM_DEV_CONNECTION=scm:git:ssh://[email protected]/BaronZ/android-common-library.git #开源协议 POM_LICENCE_NAME=The Apache Software License, Version 2.0 POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENCE_DIST=repo POM_DEVELOPER_ID=zzb POM_DEVELOPER_NAME=ZZB POM_DEVELOPER_EMAIL=[email protected] POM_DEVELOPER_URL=http://baronz.github.io GIT_URL=https://github.com/BaronZ/android-common-library.git ISSUE_URL=https://github.com/BaronZ/android-common-library/issues
4.项目目录下build.gradle,dependencies添加引用
dependencies { classpath ‘com.android.tools.build:gradle:1.2.3‘ classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2‘ }
5.项目目录下gradle目录添加文件gradle-jcenter-push.gradle,内容如下
apply plugin: ‘maven-publish‘ apply plugin: ‘com.jfrog.bintray‘ publishing { publications { mavenJava(MavenPublication) { groupId GROUP version VERSION_NAME artifactId POM_ARTIFACT_ID artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar" artifact androidJavadocsJar artifact androidSourcesJar pom.withXml { Node root = asNode() root.appendNode(‘name‘, POM_ARTIFACT_ID) root.appendNode(‘description‘, POM_DESCRIPTION) root.appendNode(‘url‘, POM_URL) def issues = root.appendNode(‘issueManagement‘) issues.appendNode(‘system‘, ‘github‘) issues.appendNode(‘url‘, ISSUE_URL) def scm = root.appendNode(‘scm‘) scm.appendNode(‘url‘, POM_SCM_URL) scm.appendNode(‘connection‘, POM_SCM_CONNECTION) scm.appendNode(‘developerConnection‘, POM_SCM_DEV_CONNECTION) def license = root.appendNode(‘licenses‘).appendNode(‘license‘) license.appendNode(‘name‘, POM_LICENCE_NAME) license.appendNode(‘url‘, POM_LICENCE_URL) license.appendNode(‘distribution‘, POM_LICENCE_DIST) } } } } def getBintrayUserProperty() { return hasProperty(‘BINTRAY_USER‘) ? BINTRAY_USER : "" } def getBintrayApiKeyProperty() { return hasProperty(‘BINTRAY_APIKEY‘) ? BINTRAY_APIKEY : "" } // gradle bintrayUpload bintray { user = getBintrayUserProperty() key = getBintrayApiKeyProperty() publications = [‘mavenJava‘] dryRun = false publish = true pkg { repo = ‘maven‘ name = POM_ARTIFACT_ID desc = POM_NAME websiteUrl = POM_URL issueTrackerUrl = ISSUE_URL vcsUrl = GIT_URL licenses = [‘Apache-2.0‘] labels = [‘android‘, ‘aar‘] publicDownloadNumbers = true version { name = VERSION_NAME vcsTag = VERSION_NAME } } }
6.项目目录下gradle目录添加文件android-artifacts.gradle,内容如下
task androidJavadocs(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { classifier = ‘javadoc‘ from androidJavadocs.destinationDir } task androidSourcesJar(type: Jar) { classifier = ‘sources‘ from android.sourceSets.main.java.sourceFiles }
7.在library目录下的build.gradle底部添加下面两行脚本
apply from: rootProject.file(‘gradle/android-artifacts.gradle‘) apply from: rootProject.file(‘gradle/gradle-jcenter-push.gradle‘)
8.登录bintray.com创建maven库
- 点击maven
- 点击Add New Package
- 填入相应的信息,再点Create Package即可
- 回到bintray主页,点击edit
- 点击API Key
- 点击show,记下你的API Key,等下要用
9.找到你home目录下的gradle.properties(windows下目录是C:\Users\你的电脑名称\.gradle),添加下面现行脚本
BINTRAY_USER=你的bintray.com的用户名 BINTRAY_APIKEY=上面一步让你记下的API Key
10.好了,敲下面命令,坐等上传成功,cmd->进入你的项目目录(注,执行下面的命令,请确保设置好环境变量,path里面有gradle/bin,有JAVA_HOME环境变量)
gradle clean build bintrayUpload
如果看到执行结果如下,那么恭喜你,坐等审核通过就可以引用了
时间: 2024-10-03 19:37:04