码迷,mamicode.com
首页 > Web开发 > 详细

使用gradle上传项目到jcenter

时间:2015-07-20 19:09:09      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

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://git@github.com/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=realbo89@outlook.com
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
View Code

 

4.项目目录下build.gradle,dependencies添加引用

技术分享
dependencies {
        classpath ‘com.android.tools.build:gradle:1.2.3‘
        classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2‘
    }
View Code

 

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
        }
    }
}
View Code

 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
}
View Code

 7.在library目录下的build.gradle底部添加下面两行脚本

技术分享
apply from: rootProject.file(‘gradle/android-artifacts.gradle‘)
apply from: rootProject.file(‘gradle/gradle-jcenter-push.gradle‘)
View Code

 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
View Code

10.好了,敲下面命令,坐等上传成功,cmd->进入你的项目目录(注,执行下面的命令,请确保设置好环境变量,path里面有gradle/bin,有JAVA_HOME环境变量)

gradle clean build bintrayUpload

 如果看到执行结果如下,那么恭喜你,坐等审核通过就可以引用了

技术分享

使用gradle上传项目到jcenter

标签:

原文地址:http://www.cnblogs.com/baron89/p/4662066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!