使用Gradle关闭并发布Maven中央仓库的构件

8

我有这个gradle脚本:

def configureUploadArtifacts(groupId, repoUrl, _packaging) {
    def gpgKeyId = System.getenv('GPG_KEY_ID')
    def gpgPassword = System.getenv('GPG_KEY_PASSWORD')
    def gpgFile = System.getenv('PATH_TO_GPG_FILE')

    project.group = groupId;
    project.archivesBaseName = name
    project.version = getVersionNameFromFile()

    ext."signing.keyId" = gpgKeyId
    ext."signing.password" = gpgPassword
    ext."signing.secretKeyRingFile" = gpgFile

    uploadArchives {
        apply plugin: 'maven'
        apply plugin: 'signing'

        signing {
            sign configurations.archives
        }

        def userName = System.getenv('OSSRH_USER_NAME');
        def password = System.getenv('OSSRH_PASSWORD');

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

                repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                    authentication(userName: userName, password: password)
                }

                snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                    authentication(userName: userName, password: password)
                }

                pom.project {
                    name "${project.name}"  
                    packaging "${_packaging}"

                    // optionally artifactId can be defined here
                    description 'A collection of core tools I use'
                    url "http://github.com/${repoUrl}"

                    scm {
                        connection "scm:git:git://github.com/${repoUrl}.git"
                        developerConnection "scm:git:ssh://github.com/${repoUrl}.git"
                        url "http://github.com/${repoUrl}/tree/master"
                    }

                    licenses {
                        license {
                            name 'The Apache License, Version 2.0'
                            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    developers {
                        developer {
                            id 'TacB0sS'
                            name 'My Name'
                            email 'My Email'
                        }
                    }
                }
            }
        }
    }
}

我在我的Jenkins服务器上使用它,它运行得非常好。 我也希望它能关闭并发布构件... 我该怎么做呢?


“close” 是什么意思? - Gonzalo Matheu
手动的过程是上传、关闭...释放。 - TacB0sS
OSSRH_USER_NAME是什么?是登录Sonatype网站的凭据吗?还是从https://oss.sonatype.org/#profile;User%20Token获取的令牌和密码? - Dr.jacky
Sonatype登录用户名 - TacB0sS
2个回答

1

你可以在你的脚本中使用gradle-release。它的工作方式类似于maven-release-plugin(从版本中删除SNAPSHOT,构建,创建标签,部署工件并更新到下一个开发版本):

apply plugin: 'net.researchgate.release'

在Jenkins中,使用发布插件,您需要配置无人值守发布
gradle release -Prelease.useAutomaticVersion=true \
               -Prelease.releaseVersion=$VERSION  \
               -Prelease.newVersion=$NEXT_VERSION

这个插件可以从多项目Gradle项目构建构件,将它们上传到Maven中央仓库,关闭并发布暂存库。 - TacB0sS

1
解决方案是将以下内容添加到根build.gradle文件中:
ext."oss-releases.username" = System.getenv('OSSRH_USER_NAME')
ext."oss-releases.password" = System.getenv('OSSRH_PASSWORD')
ext."oss-releases.url" = "https://oss.sonatype.org/index.html#stagingRepositories"

apply plugin: 'nexus-workflow'

在命令行中运行以下内容:

bash gradlew nexusStagingRelease

完成!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接