preface

About JCenter abandoned this thing, I believe many friends have already known. A few months ago, I also wrote a special article analyzing the process of JCenter abandonment. If you are interested, you can read this article about the event of JCenter being discontinued

Several key points were mentioned in the above article:

  1. JCenter will not accept any new library submissions after March 31, 2021.

  1. After February 1, 2022, JCenter will stop providing library downloads.

  1. Google will post on its Android developer website how to move open source libraries out of JCenter.

The overall plan at that time was like this, and then a few months went by, and I have to say that the plan never catches up with the change.

change

First of all, Google has changed the announcement on the Android developer website to no longer mention a plan to move out. It’s just a matter of informing open source library publishers that future library recommendations should be published on MavenCentral. And tell users of open source libraries that you have to find out exactly where those libraries are.

Google’s move to scrap JCenter has nothing to do with “me”, it’s between third-party developers and JCenter.

At the time, I saw Google’s revised announcement and thought, what about the migration of the old library? Google doesn’t care at all.

But on closer inspection, I realized that JCenter had also changed its statement. In JCenter’s latest announcement, the one that stopped downloading services after February 1, 2022 was removed. That is, while JCenter no longer allows developers to submit new libraries to it, the old libraries that have been uploaded will continue to be available for download, so there is no need to migrate them.

I don’t know why JCenter changed their attitude to doing such a good deed, but I wonder if Google negotiated something with them behind closed doors. However, this is a good thing for open source library developers, which means we don’t have to worry about old libraries anymore.

Google has given its official stance, advising developers to publish libraries to MavenCentral in the future.

The official attitude is important, because JCenter has been helped by Google in the past (and Google got screwed), or JCenter would not have made such a big impact on Android.

If you are now creating a new project using the latest version of Android Studio, you will notice that the repository declaration in the build.gradle file looks something like this:

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter() 
    }
}

Copy the code

As you can see, the mavenCentral() repository becomes the default repository for project creation, while the JCenter () repository is marked as obsolete.

Many domestic developers may find Mavan Central too cumbersome and not nearly as easy to use as JitPack.

The problem with JitPack, however, is that it is not officially recommended by Google. If you publish your library to JitPack, developers will have to import the JitPack repository to use your library, which increases the cost of using it.

So, even if it’s a hassle, I recommend that developers publish their open source libraries to MavenCentral.

Compared to JCenter, Mavan Central has much higher publishing standards. Not only is the operation more troublesome, but MavenCentral also checks to see if you own the domain name corresponding to the package path.

For example, if you submit a library, its package path format is as follows:

Com. Example. The test: the library: 1.0.0Copy the code

Then you must have the domain name example.com.

JCenter, by contrast, does not check whether you actually own the domain name at all, and the package path belongs to whoever first submits the library that uses it.

Also, it costs money to register your domain name. If you don’t want to pay, you can use GitHub to do it, but then your package path must prefix with IO. GitHub instead of using a custom package path.

This article describes how to submit to MavenCentral using your own domain name. If you want to learn how to use the IO. Github domain name, you can refer to this article to publish Android Lib to MavenCentral.

So need not say much, domain name is to want oneself to prepare for certainly first. I registered a domain name on Aliyun called guolindev.com, so I can use the package path prefixed with com.guolindev.

Next visit the following address to register a Sonatype account:

Issues.sonatype.org/secure/Dash…

After registration, re-access the address to access the Sonatype Dashboard.

Now click the Create button on the top toolbar to Create a work order:

Although this work order looks like a lot of things to fill in, it is actually very simple. Here is a screenshot of a work order I filled in:

We only need to fill in the required fields with an asterisk.

  • Leave Project and Issue Type as default.
  • You can fill in the Summary as you like. Here, I filled in the project name.
  • The Group Id is very important and determines what the package path of the library is. The prefix uses the inversion of the domain name you just applied for, and then you can customize some paths associated with the library name.
  • Project URL Enter the Github address of the Project.
  • For the SCM URL, add the.git suffix to the Github address above.

Click Create to Create the work order.

After creating the completion order, you need to wait for the staff to review it. I tested that no one will review your work order during non-working hours. So if you create a work order on a weekend, it can take two or three days for someone to process it.

After a worker processes your work order, he will leave a comment on your work order, as shown in the picture below:

This comment means that you need to prove that the domain name corresponding to the package path specified in the Group Id is yours.

To prove this, add a parse of type TXT to your domain name and point it to the URL of your work order.

If your domain name is registered in Aliyun, you can go to the domain name management interface, click Resolve on the domain name, and then add resolution records as shown in the example below:

After adding the parse record, you need to reply in the worksheet. You can simply comment “Done”. The staff will verify that the resolution record you added is valid, and will tell you that your application has been approved in the comments:

From the comments, we now have permission to publish the library to s01.oss.sonatype.org.

MavenCentral also requires that all published libraries be signed using GPG, so we’ll do that.

GPG is built in on some Linux systems, you can install it with the following command if your Linux system does not have one:

sudo apt install gnupg

Copy the code

The Mac system can be installed using HomeBrew as follows:

brew install gpg

Copy the code

For Windows, you need to visit the following address to manually download and install:

www.gnupg.org/download/

Once the installation is complete, type the following command to create the key:

gpg --full-generate-key

Copy the code

A series of options will pop up for you to choose, such as the type of key, the length of the key, and the expiration date of the key. If there are no special requirements, press Enter all the way and use the default options.

In addition, you will be asked to fill in your name, email address, and password for the key.

Once you have filled in all of the above, you should see the key you created:

Next, we need to upload the newly created key to the GPG server. So MavenCentral can get our key from the GPG server and verify the uploaded package.

The upload command is as follows:

gpg --keyserver hkp://pgp.mit.edu --send-keys C37AF927

Copy the code

Note that the last key ID used after send-keys is the last 8 bits of the key ID you just created. It’s important to use the last 8 bits, because I’ve been making weird errors using the full key ID.

As a final step, run the following command to generate the private key file:

GPG --export-secret-keys -o File path /secring.gpgCopy the code

The private key file must be saved locally and will be used later when submitting the library.

With all of the above steps completed, it’s time to release the open source library we’ve written.

release

To make the publishing process easier, I used a third-party open source plugin called Gradle-Maven-publish-plugin. You can do the same with the official Maven-publish plugin, but with a lot of extra code.

The gradle-maven-publish-plugin plugin is an open source library.

Github.com/vanniktech/…

To use this library, just copy and paste the following code at the bottom of the build.gradle file in the module where you want to publish the open source library:

. buildscript { repositories { mavenCentral() } dependencies { classpath 'com. Vanniktech: gradle - maven - publish - plugin: 0.17.0'}} allprojects {plugins. WithId (" com. Vanniktech. Maven. Publish ") { mavenPublish { sonatypeHost = "S01" } } } apply plugin: "com.vanniktech.maven.publish"Copy the code

Open the gradle.properties file in the root directory of your project and fill it with the following:

GROUP=com.guolindev. Glance POM_ARTIFACT_ID=glance VERSION_NAME=1.0.0 POM_NAME= glance POM_DESCRIPTION=A simple and handy Android database debugging library. POM_INCEPTION_YEAR=2020 POM_URL=https://github.com/guolindev/Glance/ POM_LICENSE_NAME=The Apache Software License, Version 2.0 POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt POM_LICENSE_DIST = repo POM_SCM_URL=https://github.com/guolindev/Glance/ POM_SCM_CONNECTION=scm:git:git://github.com/guolindev/Glance.git POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com/guolindev/Glance.git POM_DEVELOPER_ID=guolindev POM_DEVELOPER_NAME=Lin Guo POM_DEVELOPER_URL=https://github.com/guolindev/ signing. KeyId = key ID after eight signing. The password = key password Signing. SecretKeyRingFile = private key file path mavenCentralUsername = mavenCentralPassword = Sonatype Sonatype account passwordCopy the code

The first three elements of this template determine the package path of your open source library. For example, as I wrote above, the package path of the open source library would be:

Com. Guolindev. Glance: glance: 1.0.0Copy the code

A few other items are mostly some illustrative content, according to their actual situation to fill it.

Finally, fill in the key section with the public key ID and password you just created, the file path for the private key, and the Sonatype account password.

Because we put a lot of privacy in this file, be sure to keep it out of version control.

You can now publish the library by going to the Publish task on the Gradle TAB on the toolbar on the right side of Android Studio and double-clicking it.

If all goes well, you should be able to see in the console that the library has been published successfully.

But we’re not done here.

It should be noted that we did not publish the library to MavenCentral, and MavenCentral does not allow us to publish the library directly.

Reviewing the work order created at the beginning, what did the staff reply to us?

As you can see, we can only publish the library to the address s01.oss.sonatype.org, which is not MavenCentral.

This is also confirmed by the release script we just wrote in the build.gradle file:

allprojects {
    plugins.withId("com.vanniktech.maven.publish") {
        mavenPublish {
            sonatypeHost = "S01"
        }
    }
}

Copy the code

SonatypeHost is specified as S01, which refers to publishing the library to s01.oss.sonatype.org.

So how do YOU publish libraries to Mavan Central? And then we need to do some synchronization.

Visit the following url and log in using your Sonatype account password (the login button is in the upper right corner of the page) :

s01.oss.sonatype.org/

After a successful login, a Staging Repositories option will appear in the left sidebar of the page:

Click this option to see the newly released open source library:

Now we need to synchronize this library to the Mavan Central repository. The operation method is to check the warehouse, and then click the Close button to Close the warehouse, and click Confirm in the pop-up confirmation window.

After closing, refresh the screen and you’ll notice that the Release button is now clickable:

Click the Release button and click Confirm in the pop-up window to synchronize the open source library to MavenCentral.

After a while, you’ll see a new message in the workorder screen you created earlier:

This tells us that synchronization has already started, which usually takes about 30 minutes. However, it may take up to 4 hours to find our submitted warehouse in search.maven.org.

I didn’t verify how long the synchronization took. Anyway, I clicked the Release button and searched search.maven.org the next day, and I could find the library submitted yesterday:

If you want to reference the library in your project after submission, you can write:

Dependencies {implementation 'com. Guolindev. Glance: glance: 1.0.0'}Copy the code

It is written the same way as before using the JCenter repository.

At this point, we’ve gone through all the procedures for publishing open source libraries to Mavan Central. By following these steps, you can successfully publish your library to Mavan Central.