android - 通过 BinTray 部署 AAR 到 MavenCentral

标签 android build.gradle bintray maven-central

我是 android 开发的新手,我正在尝试通过 BinTray 将基本测试库(我正在为学习目的而构建)部署到 JCenter 和 MavenCentral。我已通过 BinTray 成功部署到 JCenter,但无法继续成功部署到 MavenCentral。

下面是我遇到的 MavenCentral REST API 错误:

HTTP/1.1 400 Bad Request [messages:[Invalid POM: /pro/johnfoley/androidTesting/testlibrary/1.0.5/testlibrary-1.0.5.pom: Project name missing, Project description missing, Project URL missing, License information missing, SCM URL missing, Developer information missing, Dropping existing partial staging repository.], status:Validation Failed]
11:45:57 AM: External task execution finished 'bintrayUpload'.

这是我的build.gradle:

apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

description = 'A test library'
group = 'pro.johnfoley.androidTesting'
version = '1.0.5'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    apply plugin: 'maven'
    apply plugin: 'maven-publish'
}


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

// Generate source JAR
task generateSourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier 'sources'
}

// Generate JavaDocs and JavaDocs JAR
task generateJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath()
            .join(File.pathSeparator))
}
task generateJavadocsJar(type: Jar) {
    from generateJavadocs.destinationDir
    classifier 'javadoc'
}
generateJavadocsJar.dependsOn generateJavadocs

artifacts
{
    archives generateSourcesJar
    archives generateJavadocsJar
}

def bintrayUser = 'BT_USER'
def bintrayApiKey = 'BT_KEY'
def bintrayGPGPassword = 'BT_PW'
def mavenCentralToken = 'MC_TOKEN'
def mavenCentralPassword = 'MC_PW'

// BinTray config
bintray
{
    user = bintrayUser
    key = bintrayApiKey

    pkg
    {
        repo = 'maven'
        name = 'pro.johnfoley.androidTesting.testlibrary'
        desc = ''
        licenses = ['Apache-2.0']
        vcsUrl = 'https://github.com/johnlfoleyiii/androidTesting.git'
        issueTrackerUrl = 'https://github.com/johnlfoleyiii/androidTesting/issues'
        websiteUrl = 'https://github.com/johnlfoleyiii/androidTesting'
        labels = []
        publicDownloadNumbers = true

        version {
            name = '1.0.5-testlibrary'
            desc = 'My test library'
            released  = new Date()
            vcsTag = 'v1.0'
            gpg {
                sign = true
                passphrase = bintrayGPGPassword
            }
            mavenCentralSync {
                sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
                user = mavenCentralToken
                password = mavenCentralPassword
                close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
            }
        }
    }

    configurations = ['archives']
}

这是从 build.gradle 生成的 POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pro.johnfoley.androidTesting</groupId>
  <artifactId>testlibrary</artifactId>
  <version>1.0.5</version>
  <packaging>aar</packaging>
  <dependencies>
    <dependency>
      <groupId>com.android.support</groupId>
      <artifactId>appcompat-v7</artifactId>
      <version>23.4.0</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

如何配置 build.gradle 以通过 BinTray 成功部署到 MavenCentral?

最佳答案

我使用 Bintray 将我的一些库上传到 Maven Central。我使用 Novoda 的 bintray-release 库创建一个 pom 并将该库上传到 Bintray。

您可以在此处按照 bintray-release 插件的项目设置进行操作:RxAnimationBinding .


在你为 bintray-upload 做了一个类比项目设置后,你可以将你的库上传到 Bintray(一定要将 dryRun 设置为 false 对于真正的上传):

./gradlew clean build bintrayUpload

上传的 repo 必须使用您的 GPG key 签名。为此,您必须:

  1. Bintray 配置文件设置中设置您的 GPG 公钥:

gpg

  1. 从这些设置中获取 API key :

api key

  1. 向 Bintray api 发送正确的调用(为此我使用 Postman 应用程序)

postman


之后你可以将你的仓库同步到 Maven

sync

关于android - 通过 BinTray 部署 AAR 到 MavenCentral,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37328415/

相关文章:

java - 无法解决 Gradle 依赖项的构建失败异常

android - Gradle versionName 和 versionCode 在 3.0 更新后不工作

java - 如何使用 maven/travis 将二进制文件打包、压缩并部署为 zip/tar.gz 从 github 存储库到 bintray.com 通用存储库

bintray - 在 bintray 上自己的存储库之间移动包

android - 如何在android中使用磁力计查找磁场强度

android - 重新安装 cordova 应用程序后,如何自动重新连接 Chrome DevTools?

java - Gradle 'exclude' 本地 `fileTree` 来自子项目的传递依赖

gradle - bintray - 将多模块 Gradle 工件发布到 JCenter

javascript - 用 native react 控制顶部栏

android - 使用 RoboSpice 并行执行