无法使用 Gradle 将工件发布到 Nexus maven 存储库

Unable to publish artifacts to Nexus maven repository using Gradle

我是 Gradle、nexus 和 Maven 的新手,正在尝试使用 Gradle 'publish' 任务将 Jenkins 的 maven 工件发布到新的 nexus 存储库。 Jenkins 作业在发布时失败并出现以下错误。我在作业中提供了Nexus的用户名和密码。


:common-test:publishMavenJavaPublicationToMavenRepositoryCould not find metadata 
com.xx.audit:common-test:1.0.3-SNAPSHOT/maven-metadata.xml in
 remote (https://nexus.xx.com:8443/content/repositories/snapshots)

Upload https://nexus.xx.com:8443/content/repositories/snapshots/yy/audit/common-test/1.0.3-SNAPSHOT/common-test-1.0.3-20151102.120123-1.jar
Could not transfer artifact com.xx.audit:common-test:jar:1.0.3-20151102.120123-1 
from/to remote (https://nexus.xx.com:8443/content/repositories/snapshots):
 Could not write to resource 'yy/audit/common-test/1.0.3-SNAPSHOT/common-test-1.0.3-20151102.120123-1.jar'

第一次发布之前需要在nexus maven仓库中创建文件夹结构吗?并添加 maven-metadata.xml? *.pom.sha, *.pom.md5 是怎么生成的。 请帮我解决这个问题。

build.gradle配置:

  apply plugin: "maven-publish"

    //* New Gradle task to jar source
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    //* New Gradle task to jar javadoc
    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java

                artifact sourcesJar {
                    classifier "sources"
                }
            }
        }
    }

    publishing {
        repositories {
            maven {
                credentials {
                    username nexusUsername
                    password nexusPassword
                }   
                if (project.version.endsWith('-SNAPSHOT')) {
                    url nexusSnapshotRepoURL
                } else {
                    url nexusReleaseRepoURL
                }   
            }   
        }
    }

我不知道 maven-publish Gradle 插件。通常使用 uploadArchives 任务。 Nexus book examples project 中提供了其用法的完整示例。将其用作测试您的凭据和设置的参考。