通过BinTray将AAR部署到MavenCentral

时间:2016-05-19 15:55:31

标签: 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?

1 个答案:

答案 0 :(得分:0)

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

您可以按照bintray-release插件的项目设置进行操作,例如:RxAnimationBinding

在您为bintray-upload进行类比项目设置后,您可以将您的库上传到Bintray(确保将dryRun设置为false以进行实际上传) :

./gradlew clean build bintrayUpload

上传的回购必须使用您的GPG密钥签名。要做到这一点,你必须:

  1. Bintray个人资料设置中设置您的GPG公钥:
  2. gpg

    1. 从这些设置中获取API密钥:
    2. api key

      1. 向Bintray api发送正确的电话(我使用Postman应用程序)
      2. postman

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

        sync