美文网首页
使用bintray-release快速发布库到JCenter

使用bintray-release快速发布库到JCenter

作者: 编码前线 | 来源:发表于2018-06-03 23:18 被阅读1次
    1. 前往https://bintray.com/ 注册账号

    2. 在bintray中创建一个maven仓库


      create_maven_repository.png
    1. 在Android项目中的根build.gradle中,添加如下代码:
    dependencies {
        // ...
        classpath 'com.novoda:bintray-release:0.5.0'
    }
    
    1. 在local.properties文件中添加bintray的用户名和API key
    bintray.user=xxxxx
    bintray.key=xxxxxxxx
    
    1. 在项目根目录下创建secret.gradle用于读取local.properties中配置的用户名和API KEy
    //加载资源
    Properties properties = new Properties()
    InputStream inputStream = project.rootProject.file('local.properties').newDataInputStream()
    properties.load( inputStream )
    
    //读取字段
    ext.bintray_key = properties.getProperty('bintray.key')
    ext.bintray_user = properties.getProperty('bintray.user')
    
    1. 在library所在的module中的build.gradle中,添加bintray-release插件的应用和secret.gradle的配置;
    apply plugin: 'com.novoda.bintray-release'
    apply from: rootProject.file("secret.gradle")
    
    1. 在library所在的module中的build.gradle中,添加发布到JCenter的参数配置;
    publish {
        userOrg = 'xch168'            // bintray.com用户名
        groupId = 'com.github.xch168' // jcenter上的路径
        artifactId = 'androidUtil'    // 项目名称
        publishVersion = '0.0.5'      // 版本号
        desc = 'Oh hi, this is a nice description for a project, right?' // 描述,不重要
        website = 'https://github.com/xch168/AndroidUtil'                // 网站,不重要;可以填写GitHub中的项目地址
    
        bintrayUser = bintray_user // bintray.com的用户名
        bintrayKey = bintray_key   // bintray.com的API key
    }
    
    1. 在项目根目录下创建快速发布脚本publish.sh(Mac OS) or publish.bat(Windows)
    // Mac OS
    ./gradlew clean build generatePomFileForReleasePublication bintrayUpload -PdryRun=false
    
    // Windows
    gradlew clean build generatePomFileForReleasePublication bintrayUpload -PdryRun=false
    
    1. 执行publish脚本,发布项目,项目发布成功后进入bintray.com,可以看到如下:


      library_maven.png
    2. 将项目同步到JCenter(需要等待审核)


      add_to_jcenter.png
      jcenter.png
    3. 使用自己发布的库

    compile 'com.github.xch168:androidUtil:0.0.5'
    

    相关文章

      网友评论

          本文标题:使用bintray-release快速发布库到JCenter

          本文链接:https://www.haomeiwen.com/subject/dxissftx.html