Search code examples
jarsonatypemvn-repo

Publishing a jar to MVN central


I'm trying to publish my JAR to maven Central I followed every step given here. The last step mentioned there is

gradle uploadArchives

Which worked, and said successfully uploaded. but when I go to release site, I don't see my jar there to release. What am I missing?

enter image description here


Solution

  • gradle uploadArchives is successful doesn't always mean your artifact will be available for release (Sonatype calls them staging repository).

    For my case my Artifact version was 1.0.0-Snapshot. as I had SnapShot keyword in my version number it was actually released to SnapShot repository . When I removed snapshot word from my version and redeployed it was available in staging and i was able to release it to mvn central

    Steps for publishing -

    • Create an account
    • Create a new Sonatype Open Source Project Repository Hosting OSSRH
    • Your Project will be created . Wait for the ticket to resolve
    • Create a gpg key . (brew install gpg2 , gpg --gen-key, gpg --list-keys, gpg --keyserver hkp://pool.sks-keyservers.net --send-keys CCB2F39ADC112552658A3EA60A1189B4C4B4D83B)
    • Follow this to generate build.gradle.
    • create gradle.properties in your root and add to .gitignore.Add secret
    signing.keyId=C4B4D83B  #(gpg --list-keys , last 8 digit )
    signing.password=z_*** #(password that you used to sign keys)
    signing.secretKeyRingFile=/Users/<ur machine username>/.gnupg/secring.gpg
    ossrhUsername=sapy
    ossrhPassword=<ossrhpassword from google key chain>
    
    • to upload your changes to sonatype release manager - gradle uploadArchives
    • Dont forget to remove snapshot from version ,
    • Now go to (https://oss.sonatype.org/#stagingRepositories) , select your repository , check, and click on close. It takes some time to close.
    • Once you have successfully closed the staging repository, you can release it by pressing the Release button. This will move the components into the release repository of OSSRH where it will be synced to the Central Repository.
    • If some of the guideline fails you will see the steps that failed in Red. and 'Release' button will not be activated. Drop it and re upload and reclose.
    • Last 3 steps are well documented here and here
    • After 10 minutes to 2hrs . Your changes will reflect search.maven.org.
    • changes should be available immediately after release in release site