Close and release artifact on maven central using gradle
Asked Answered
L

2

8

I have this gradle script:

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'
                        }
                    }
                }
            }
        }
    }
}

I use it on my Jenkins server and it works wonderfully. I would like it also to close and release the artifacts... How do I do that?

Lutero answered 28/8, 2017 at 19:54 Comment(4)
What do you mean by close?Canaster
The manual process is to upload, close... release.Lutero
What is OSSRH_USER_NAME? The sonatype login to website credentials? OR token and password from oss.sonatype.org/#profile;User%20Token ?Roa
Literally sonatype login usernameLutero
L
1

Solution was to add the following to the root build.gradle file:

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'

And run the following from the command line:

bash gradlew nexusStagingRelease

DONE!

Lutero answered 26/9, 2017 at 11:47 Comment(0)
C
1

You can use gradle-release on your script. It works similar as maven-release-plugin (removes SNAPSHOT from version, builds, create tags, deploys artifacts and updates to the next development version):

apply plugin: 'net.researchgate.release'

In Jenkins, using release plugin, you will need to configure the unattended release:

gradle release -Prelease.useAutomaticVersion=true \
               -Prelease.releaseVersion=$VERSION  \
               -Prelease.newVersion=$NEXT_VERSION
Canaster answered 4/9, 2017 at 21:38 Comment(1)
This plugin can build artifacts from multi-project gradle project, upload them to Maven central, close and release the staging repository?Lutero
L
1

Solution was to add the following to the root build.gradle file:

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'

And run the following from the command line:

bash gradlew nexusStagingRelease

DONE!

Lutero answered 26/9, 2017 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.