发布开源项目到Jcenter从0到1,自身经历

把自己的依赖放到JCenter 首先需要注册Bintray ,因为Bintray 是 JCenter 库的运营商。

  1. 首先你要有一个项目,准确的说应该有一个Android moudle并把项目上传到GitHub

  2. 注册 :网址https://bintray.com/signup/oss这里注册一定要注册个人账号

    在这里插入图片描述

  3. Add New Repository

    在这里插入图片描述

    在这里插入图片描述


  4. Repository添加成功后会跳转到Repository首页,接下来需要Add a Package

    在这里插入图片描述

  5. package添加成功后去package主页Add a Version

    在这里插入图片描述


    到此,在Bintray上的操作就告一段落

    现在回到AndroidStudio进行配置

  6. 在Project的build.gradle添加依赖(项目最外层build.gradle)

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        //以下两项依赖需要添加
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4"
        classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
    
  7. 在local.properties配置Bintray的用户名和Apikey

    bintray.user=你的用户名
    bintray.apikey=你的apikey
    
  8. 在moudle的build.gradle添加如下属性注意是最上面(在apply plugin: 'com.android.library’之上)

    ext {
        bintrayRepo = 'appUpdate' // 之前添加的Repository name
        bintrayName = 'com.sanzhi.appupdate' // 之前添加的package name
        publishedGroupId = 'com.sanzhi.appupdate'   // 默认应该和package name一样 this is the ID we want to see in implementation line
        libraryName = 'appupdate'     // moudle的名称this is the module name of library
        artifact = 'appupdate'        // moudle的名称this is the artifact we want to see in implementation line
        libraryDescription = 'self app updata library' // description of library
        siteUrl = 'https://github.com/parade0393/AppUpdate'    // 项目再github的主页git repo url
        gitUrl = 'https://github.com/parade0393/AppUpdate.git' // 项目再GitHub的仓库地址git repo vcs url
        libraryVersion = '1.0.0'      // 之前添加的版本号library version后续更新也是改这个版本号
        developerId = 'parad0393'                // This is your bintray username
        developerName = 'parad0393'              // Developer's name
        developerEmail = 'parade0379@gmail.com'                // Developer's email
        licenseName = 'The Apache Software License, Version 2.0'  // for example, The Apache Software License, Version 2.0
        licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'   // for example, http://www.apache.org/licenses/LICENSE-2.0.txt
        allLicenses = ["Apache-2.0"]    // array of licenses, for example, ["Apache-2.0"]
    }
    
  9. 在moudle下新建publish.gradle文件,并在文件添加如下内容

    apply plugin: 'com.jfrog.bintray'
    apply plugin: 'com.github.dcendents.android-maven'
    version = libraryVersion
    group = publishedGroupId    // Maven Group ID for the artifact
    install {
        repositories.mavenInstaller {
            // This generates POM.xml with proper parameters
            pom {
                project {
                    packaging 'aar'
                    // Add your description here
                    name libraryName
                    description libraryDescription
                    url siteUrl
                    // Set your license
                    licenses {
                        license {
                            name licenseName
                            url licenseUrl
                        }
                    }
                    developers {
                        developer {
                            id developerId
                            name developerName
                            email developerEmail
                        }
                    }
                    scm {
                        connection gitUrl
                        developerConnection gitUrl
                        url siteUrl
                    }
                }
            }
        }
    }
    task sourcesJar(type: Jar) {
        from android.sourceSets.main.java.srcDirs
        archiveClassifier  = 'sources'
    }
    artifacts {
        archives sourcesJar
    }
    // Bintray
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    bintray {
        user = properties.getProperty("bintray.user")
        key = properties.getProperty("bintray.apikey")
        configurations = ['archives']
        pkg {
            repo = bintrayRepo
            name = bintrayName
            desc = libraryDescription
            websiteUrl = siteUrl
            vcsUrl = gitUrl
            licenses = allLicenses
            publish = true
            publicDownloadNumbers = true
            version {
                desc = libraryDescription
            }
        }
    }
    //这里不需要做修改
    
  10. 回到moudle的build.gradle在apply plugin: 'com.android.library’后面添加apply from: ‘publish.gradle’

  11. 至此在AndroidStudio配置完成,接下来就是打包上传到Bintray,在Studio的terminal中依次输入以下两个命令

    gradlew install
    gradlew bintrayUpload
    
  12. 正常情况下执行完以上两个命令,代码就已经上传到Bintray里,现在还剩最后一步,回到Bintray,打开本package页面 Add to Jcenter

    在这里插入图片描述

  13. 等待审核通过就可以在AndroidStudio里直接implementation了

  14. 参考文章

    1. How to Publish an Open Source Android Library on JCenter
    2. 新版bintray教你上传JCenter仓库
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值