Gradle 将EclipseAndroid库项目上载到maven central

Gradle 将EclipseAndroid库项目上载到maven central,gradle,android-library,aar,maven-central,Gradle,Android Library,Aar,Maven Central,背景 我一直在eclipse中构建一个android库项目。它最初不是用gradle构建的,而是遵循旧的android文件夹结构 现在为了上传到maven cental 我首先在sonatype上创建了一个帐户,然后在jira上为一个新项目创建了一个问题。 他们为我的groupid com.github.amansatija创建了一份回购协议(为此,我等了两个工作日,直到问题得到解决) 现在我创建了gpg密钥对环 之后,我用gradle导出了EclipseAndroid库项目 然后我将它导入an

背景 我一直在eclipse中构建一个android库项目。它最初不是用gradle构建的,而是遵循旧的android文件夹结构

现在为了上传到maven cental 我首先在sonatype上创建了一个帐户,然后在jira上为一个新项目创建了一个问题。 他们为我的groupid com.github.amansatija创建了一份回购协议(为此,我等了两个工作日,直到问题得到解决)

现在我创建了gpg密钥对环

之后,我用gradle导出了EclipseAndroid库项目 然后我将它导入androistudio,只是为了确保它变得完全友好。。 现在,在android库项目的构建系统更改为gradle之后,我跟随chris banes maven在github上推送gradle插件,在maven上部署我的库项目

下面是gradle my系统的详细信息

我的全局gradle.properties文件(位于用户\u homer.gradle\gradle.properties的文件) 包含这个

NEXUS_USERNAME=amansatija
NEXUS_PASSWORD=mushROOM@7

signing.keyId=16DF7223
signing.password=customer360
signing.secretKeyRingFile=mitul_private_key.gpg
我的项目是 格雷德尔,这是什么

VERSION_NAME=0.0.1-SNAPSHOT
VERSION_CODE=1
GROUP=com.github.amanasatija

POM_DESCRIPTION=A demo test lib to understand maven central uploads
POM_URL=https://github.com/amansatija/Cus360MavenCentralDemoLib
POM_SCM_URL=https://github.com/amansatija/Cus360MavenCentralDemoLib
POM_SCM_CONNECTION==https://github.com/amansatija/Cus360MavenCentralDemoLib.git
POM_SCM_DEV_CONNECTION==https://github.com/amansatija/Cus360MavenCentralDemoLib.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=amansatija
POM_DEVELOPER_NAME=Aman Satija
我的项目的maven_推送文件包含以下内容

/*
 * Copyright 2013 Chris Banes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'maven'
apply plugin: 'signing'

def isReleaseBuild() {
    return VERSION_NAME.contains("SNAPSHOT") == false
}

def getReleaseRepositoryUrl() {
    return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
            : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
    return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
            : "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
    return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
println(NEXUS_PASSWORD)
println(NEXUS_USERNAME)
    return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

                pom.groupId = GROUP
                pom.artifactId = POM_ARTIFACT_ID
                pom.version = VERSION_NAME

                repository(url: getReleaseRepositoryUrl()) {
                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                }
                snapshotRepository(url: getSnapshotRepositoryUrl()) {
                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                }

                pom.project {
                    name POM_NAME
                    packaging POM_PACKAGING
                    description POM_DESCRIPTION
                    url POM_URL

                    scm {
                        url POM_SCM_URL
                        connection POM_SCM_CONNECTION
                        developerConnection POM_SCM_DEV_CONNECTION
                    }

                    licenses {
                        license {
                            name POM_LICENCE_NAME
                            url POM_LICENCE_URL
                            distribution POM_LICENCE_DIST
                        }
                    }

                    developers {
                        developer {
                            id POM_DEVELOPER_ID
                            name POM_DEVELOPER_NAME
                        }
                    }
                }
            }
        }
    }

    signing {

        required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }

    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
    }

    artifacts {
        archives androidSourcesJar
        archives androidJavadocsJar
    }
}
VERSION_NAME=0.0.1
如您所见,我已将nexus用户名和密码打印出来,脚本似乎已正确找到凭据

下面是我的lib模块的build.gradle

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.12.+'
        }
    }
    apply plugin: 'com.android.library'

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
    }

    android {
        compileSdkVersion 21
        buildToolsVersion "21.0.1"

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }

        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
                java.srcDirs = ['src']
                resources.srcDirs = ['src']
                aidl.srcDirs = ['src']
                renderscript.srcDirs = ['src']
                res.srcDirs = ['res']
                assets.srcDirs = ['assets']
            }

            // Move the tests to tests/java, tests/res, etc...
            instrumentTest.setRoot('tests')

            // Move the build types to build-types/<type>
            // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
            // This moves them out of them default location under src/<type>/... which would
            // conflict with src/ being used by the main source set.
            // Adding new build types or product flavors should be accompanied
            // by a similar customization.
            debug.setRoot('build-types/debug')
            release.setRoot('build-types/release')
        }
    }

apply from: '../maven_push.gradle'
如你所见,我已经适当地遵循了规则 但是,当我执行gradlew clean uploadArchives任务时,, 除了最后一步说失败外,一切都很顺利 拒绝访问

What went wrong:Execution failed for task ':DemoLibManvenCentral:uploadArchives'.Could not publish configuration 'archives'
Error deploying artifact 'com.github.amanasatija:library:apk': 
Error deploying artifact: Authorization failed: Access denied to: https://oss.sonatype.org/content/repositories/snapshots/com/github/amanasatija/library/0.0.1-SNAPSHOT/library-0.0.1-20141114.123550-1.apk
请帮帮我

编辑

解决方案::

所以我终于设法解决了这个问题。 显然问题是

VERSION_NAME=0.0.1-SNAPSHOT
在我的项目的gradle.properties文件中 当我把上面的行改成下面的

/*
 * Copyright 2013 Chris Banes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'maven'
apply plugin: 'signing'

def isReleaseBuild() {
    return VERSION_NAME.contains("SNAPSHOT") == false
}

def getReleaseRepositoryUrl() {
    return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
            : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
    return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
            : "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
    return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
println(NEXUS_PASSWORD)
println(NEXUS_USERNAME)
    return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

afterEvaluate { project ->
    uploadArchives {
        repositories {
            mavenDeployer {
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

                pom.groupId = GROUP
                pom.artifactId = POM_ARTIFACT_ID
                pom.version = VERSION_NAME

                repository(url: getReleaseRepositoryUrl()) {
                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                }
                snapshotRepository(url: getSnapshotRepositoryUrl()) {
                    authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                }

                pom.project {
                    name POM_NAME
                    packaging POM_PACKAGING
                    description POM_DESCRIPTION
                    url POM_URL

                    scm {
                        url POM_SCM_URL
                        connection POM_SCM_CONNECTION
                        developerConnection POM_SCM_DEV_CONNECTION
                    }

                    licenses {
                        license {
                            name POM_LICENCE_NAME
                            url POM_LICENCE_URL
                            distribution POM_LICENCE_DIST
                        }
                    }

                    developers {
                        developer {
                            id POM_DEVELOPER_ID
                            name POM_DEVELOPER_NAME
                        }
                    }
                }
            }
        }
    }

    signing {

        required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }

    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
    }

    artifacts {
        archives androidSourcesJar
        archives androidJavadocsJar
    }
}
VERSION_NAME=0.0.1
它似乎工作正常。。
标签快照导致我的工件被部署到snotype的快照repo,而快照repo由于某种原因似乎没有等待您的工件,我猜它只是想要应用程序的图片或快照

看起来您没有权限在服务器上发布com.github.amanasatija组ID的工件


在“社区支持-开放源码项目存储库托管”项目下为此提交一个问题,我们将帮助您解决此问题。

我让sonatype支持人员检查权限,他说当传递无效参数时会发生拒绝访问。。我不明白为什么会有无效的参数,除了一件事,当我在构建文件夹中查看时,我只看到apk,没有arr文件请帮助我