Automatic release in Maven Central using Gradle

I would like to upload my Jar to the Maven Central repository using gradle uploadArchives and use it in other projects as a dependency. I followed this nice tutorial , as a result of which my Jars load into Sonatype Nexus (see screenshot below).

Version 1.1 of my Jar is available; line

dependencies {compile 'eu.matthiasbraun:Utils:0.1'}

works fine in the build.gradle file of my dependent project. I released version 0.1 by clicking the Close and Release buttons shown in the screenshot. After that, I commented on the Jira ticket I created here , and he was told that central synchronization will be performed every two hours.

It was my understanding that if I wanted to release Jar 0.2 now, I would just gradle uploadArchives and change the line in the gradle file of my dependent project to

dependencies {compile 'eu.matthiasbraun:Utils:0.2'} .

However, when I gradle build my dependent project (after two hours), I received an error that the dependency could not be resolved.

Here is my complete build.gradle that loads my Jar in Sonatype Nexus: link .

How can I automate the release of Jars in Maven Central using Gradle? Thanks.

screenshot

+6
source share
3 answers

I used the nexus-workflow gradle plugin to automate the repository release.

I put this at the beginning of build.gradle my project, which I want to release:

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.adaptc.gradle:nexus-workflow:0.6' } } apply plugin: 'nexus-workflow' 

In addition, I put these three properties in ~/.gradle/gradle.properties

 oss-releases.username=mySonatypeUsername oss-releases.password=mySonatypePassword oss-releases.url=https://oss.sonatype.org/index.html#stagingRepositories 

When I want to press release on Maven Central, I first upload Jars to Nexus using gradle uploadArchives , and then I do gradle nexusStagingRelease . This closes and frees all my open repositories on Nexus.


Edit: I also found this plugin from Benjamin Muschko, which seems to be an alternative to the plugin described above. I have not tried it yet.

+8
source

You can use the Gradle Nexus Staging Plugin to automate closing the repository and promoting / releasing artifacts in Maven Central.

It should be added to your project:

 buildscript { repositories { mavenCentral() } dependencies { classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.1" } } apply plugin: 'io.codearte.nexus-staging' 

and configured:

 nexusStaging { packageGroup = "org.mycompany.myproject" stagingProfileId = "yourStagingProfileId" //optional, but reduce number of calls to Nexus } 

After the artifacts have been uploaded (using uploadArchives or in any other way), just call:

 ./gradlew closeRepository promoteRepository 

If synchronization with Maven Central has been enabled, artifacts should automatically appear in Maven Central within a few minutes.

Additional information (including ways to provide credentials) in this blog post or on the project’s webpage .

Denial of responsibility. I am the author of this plugin.

+4
source

A screenshot shows that you have not yet released your library. You just put it in OSSRH. What you need to do next -

  • Close the staging repository by clicking the Close button, this signals Nexus that nothing else is expected to be added to the staging repository
  • verify that the files in the content are approved
  • if you are happy with everything - release the components in Central by clicking the "Release" button
  • or if you are unhappy with it, click the Drop button to remove the intermediate repo and start from scratch.
  • until everything is synchronized with Central from OSSRH (takes up to an hour or a little more depending on your time).

Btw. if you can automate this on the command line using Nexus Staging Maven Plugin or Ant Tasks. And you can wrap Ant tasks and use them in Gradle. For more on all of this, see the Nexus section of the interim chapter .

0
source

Source: https://habr.com/ru/post/959500/


All Articles