📜 ⬆️ ⬇️

Publishing an artifact to Maven Central via Sonatype OSS Repository Hosting Service

At the writing of this article I was led by some fragmentation of sources of information on such
important, in my opinion, the topic, as the publication of their artifacts in the Maven Central. Of course should
pay tribute to the staff Sonatype: their official guide (link at the end of the article) quite fully
describes the whole process. But there are not some unobtrusive subtleties in it (like the problem of storing
passwords), and he himself looks a bit sloppy. I did not find any resources in Russian on this topic.
principle. For me personally, this is not scary, but it can stop many.



Probably most Java programmers know what Maven Central is. For those who do not know:
Maven Central is a huge library repository for the JVM platform. Anyone can post
There library, if its license allows public distribution. After that this library
can be specified as a dependency in the project's build system, such as Maven. Then when building the project
This system will automatically download the library and compile your project with its use. On my
look, it is the presence of Maven Central is one of the key reasons (if not the most important) success
Java as a platform. I do not know more than a single repository, which is compared to Central in the number
artifacts and usability; the only thing that comes to mind is CPAN, Comprehensive
Perl Archive Network, or Haskell's Cabal, but it's still not quite right.
')
Anyone can upload to the Central library. You can even upload not your own libraries, but
strangers that no one has ever been able to put there, but only if the library license allows
such a spread. A week ago I wrote one library and decided to post it in Central. how
it turned out to be a somewhat nontrivial process at first glance, although in general nothing supercomplex
it is not.

Initially, as far as I understood from the remnants of the documentation on this topic, artifacts in Maven Central
taken by their server using rsync. However, this was considered an unsuccessful decision, and now Maven
Central is replenished from several large trusted repositories of artifacts. That which us
interests, called Sonatype OSS Repository Hosting Service . This is a Sonatype project,
giving anyone the opportunity to share their library. Maven servers
Central syncs regularly with OSSRH, and those artifacts that the user marks as
ready for release are uploaded to the central repository.

In short, the procedure for uploading your artifact to Central looks like this: you need to register on
Sonatype JIRA and leave a ticket to open the repository; then when the repository is opened, you will need to
load artifacts into it (manually or using a special configuration of the assembly system), and then
indicate that these artifacts should be poured into Central.

Sonatype Repositories provides two, Snapshots and Staging. Snapshots repository is designed to
so-called snapshots , in fact, builds directly from the main development branch to
version control system. Staging repository is intended for releases of artifacts - those versions
which will no longer change. Staging is so called because the artifacts from it after checking
health needs to "promote" (promote) in Maven Central. After a while Maven Central
syncs with Sonatype OSSRH, and your artifacts will appear in Central.

Consider all the steps on the items.

Create a ticket on Sonatype JIRA



The first step is to open the repository, into which artifacts will be downloaded for synchronization with
Central. This is done through the ticket system in Sonatype JIRA. Link: http://issues.sonatype.org/ .

First you need to register there. On the page that opens, click the link below Sign Up . A standard registration form will open. Complete and submit it. It should be noted, however, that
in the Full Name field you need to enter exactly the full name, like “Vasiliy Pupkin”, in two words through
space. The official guide states that this is due to problems with the integration between JIRA and something
named Crowd.

After filling and sending the form, you will automatically be logged in to the system. On the main
You can find the following link in the list of projects on the left:
https://issues.sonatype.org/browse/OSSRH . This is the section in which you need to create an opening ticket.
repository To create a ticket, click the New Project button. Fields should be filled like this:


Important point: group id, I have indicated a common - org.bitbucket.googolplex , and not
org.bitbucket.googolplex.devourer . This is done with an eye to the future: suddenly you want
publish another one of your project? In this case, you will not have to start additional tickets,
the global prefix for the repositories will already belong to you. Basically, people who work
over these tickets are quite adequate and experienced, so they can change the group id for you
more general self.

The official statement says that group id should be chosen in such a way that it means
domain controlled by you. This could be your site or section on a version control service like
Github or Bitbucket (like mine, in the example above). Before you create a repository for you,
the package name will be checked and written if there are any problems with it (for example, the corresponding site
does not belong to you).

After a while, a Sonatype employee will create a set of repositories for you and close the ticket. To me
lucky, my ticket was closed almost immediately after its creation. After that you can download
artifacts in the staging repository, and from there they can be promoted (promote) in Central. However before
How to load artifacts into the repository, you need to create them. For this you need the right
how to configure the maven, i.e. your project’s pom.xml file and possibly the system file
settings mavena settings.xml .

We create and prepare artifacts for unloading.



Now there are many build systems that can create standard mavenovo artifacts: Maven,
Buildr, SBT, Gradle, Leiningen and others. The instructions below are correct for Maven version 3. In an article on the wiki
Sonatype (link at the end of this article) has instructions for using other build systems.

The essence of the concept of “artifact” in the context of maven is very simple - this is just a regular jar file with
additional meta information. This artifact description is the so-called POM , Project Object.
Model represented by pom.xml file. I will not describe the format in full here, but only indicate
those parts of the POM that must be available to successfully download the artifact to Maven Central.

So, according to the official Sonatype documentation, the pom.xml should be present in pom.xml
sections:

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


All Articles