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

时间:2015-11-02 16:40:40

标签: maven gradle build.gradle nexus

我是Gradle,nexus和Maven的新手,并尝试使用Gradle'发布'任务将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
                }   
            }   
        }
    }

1 个答案:

答案 0 :(得分:3)

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