2. Log in with your credentials.
3. Create a new Project ticket using this link.
4. Fill in the details of your library. (even though there’s sample text beneath the textfields to guide you, below is a filled form for you to get an idea):
5. Click Create.
This creates a new ticket for Sonatype to review your information. About 2–3 minutes, you’ll receive an automatic comment on your ticket saying:
Do you own the domain waseefakhtar.com? If so, please verify ownership via one of the following methods:
* Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-61704(Fastest)
* Setup a redirect to your Github page (if it does not already exist)
If you do not own this domain, please read:
http://central.sonatype.org/pages/choosing-your-coordinates.html
You may also choose a groupId that reflects your project hosting, in this case, something like io.github.waseefakhtar or com.github.waseefakhtar
Notice that they ask about the domain name based on the Group ID you’ve mentioned in the ticket description as well as your library, for instance, com.waseefakhtar in my case.
At this point, we’ll go with the first option to verify our ownership.
DNS Referencing
As I already own the domain I bought from GoDaddy, the instructions or screenshots I post in this section might differ in your case if you used another domain provider.
In this section, we assume you already have a domain and just need to add a TXT record.
- First things first, log in to your account.
- Go to your Account > My Products.
- Look for your domain and click DNS to go to DNS Management.
4. In DNS Management, under Records, click Add to add a new record.
5. Add the following information in the fields provided:
Type: TXT | Host: @ | TXT Value: [your ticket reference in Sonatype Jira] | TTL: 1 Hour
6. Click Save.
And done!
You can verify if the TXT record is correctly entered by opening up your Terminal and typing:
$ host -t txt waseefakhtar.com
Which should return:
waseefakhtar.com descriptive text "OSSRH-61704"
At this point, you should add a comment on your Jira ticket saying:
The DNS record has been added to waseefakhtar.com.
This should notify the team that they can start verifying you, which should be done within 2 business days.
When you’re finally verified, you’ll receive a comment on the ticket saying:
com.waseefakhtar has been prepared, now user(s) waseefakhtar can:
Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots
Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2
Release staged artifacts into repository ‘Releases’
please comment on this ticket when you promoted your first release, thanks
If you log in to https://oss.sonatype.org/service/local/staging/deploy/maven2 at this point, you can see there’s nothing published in your repositories yet. That’s what we’re going to do next.
Protip: Since Sonatype takes max 2 days, the whole verification steps can be done prior to or simultaneously when you’re working on the library so that once the library is ready, you can just publish it right away.
Publishing your library via Android Studio
When publishing our library, we’re going to use a Gradle plugin by Niklas Baudy which makes uploading to Sonatype OSS (Maven Central) easy: https://github.com/vanniktech/gradle-maven-publish-plugin
In order to do that:
- Open your project’s build.gradle.
- Add these lines inside buildscript:
3. Open your library’s build.gradle and add your plugin at the top, like:
4. Now, inside your library’s directory, create a new file, gradle.properties.
5. Fill in the information regarding your library by entering values for each key, similar to the following:
This should help the library pick information from when uploading.
Next, we’re going to give Android Studio access to our Sonatype OSS (Maven Central) and sign our release artifact with GPG, which is a requirement when publishing to Maven Central.
Generating a GPG Key
To create a GPG key for signing your release artifact:
- Download GPG command line tools from https://www.gnupg.org/download/ and install them.
- Open your Terminal.
- Type gpg — full-generate-key.
- When asked what kind of key you want, press Enter to select the default RSA and RSA.
- When asked about the keysize, type 4096.
- When asked about the duration of key to be valid, press Enter to select the default, indicating that the key doesn’t expire.
- When asked about the information for creating a new user ID, provide your name and email address.
- Enter ‘O’ for Okay.
- When prompted, create a passphrase to protect your key.
This creates your key in ~/.gnupg/openpgp-revocs.d/ with .rev format. Since we need our key in .gpg format, here’s how to create that:
- In your Terminal, type
gpg --export-secret-keys -o secring.gpg
. - When prompted with the passphrase, type the passphrase you set for the key you created.
This should create a file named secring.gpg in your root directory.
Configuring signing parameters
Now that we have all that we need to configure our signing parameters, we need to configure them in Android Studio.
Since we’ll be providing our key password and our OSS password, we need to make sure we provide this in a file that’s private to your system and ignored by, for instance, Git.
Therefore, we choose local.properties of your project for this configuration:
- Open local.properties.
- Type the following information, making sure they’re all correct.
For your signing.keyId, enter the last 8 digit of your .rev key (which is often the name of the file, for instance 52D3BD1C)
And we’re almost done!
Uploading your library artifact
- Open Terminal from Android Studio.
- Type ./gradlew uploadArchives — no-daemon — no-parallel.
- Press Enter.
If everything configured correctly, this should now take a while and upload your library to https://oss.sonatype.org. The only thing left to do now is to publish the library via Sonatype OSS.
Publishing the library
Once the library is finished uploading, you can go to https://oss.sonatype.org/ and under Staging Repositories, you should now see your repository appear.
In order to finally publish your library, do the following:
- Select the repository.
- Click Close from the top menu and confirm the dialog.
This should take a while and you can see the activity by clicking Activitynext to Summary in the dashboard below. Note that the Activity does not refresh by itself, so you need to refresh it to see the actual activity.
Once you see the Activity status as Last operation completed successfully in Summary, you can notice that the release action enables in the menu at the top.
3. Click Release and confirm the dialog.
That should finally make your library available in 10–15 mins. You can try using the library in any project by adding it as a dependency in your app’s build.gradle:
https://search.maven.org/, however, should take about 2 hrs to process your library and show in search.
One final thing that you should do is to go back to your ticket in Sonatype Jira and leave a comment that you’ve now promoted your first release and it works well. This should notify their team in order to mark the ticket as resolved.
And that’s about it! đ
The only thing left for you to do now is to give yourself a pat on the back as this process is a bit lengthy and confusing to most of us. So feeling proud of yourself or accomplished at this moment is the least you can do! đ
Happy coding! đť
Source code for the example library
waseefakhtar/extendedplayerview |
Have something to say? Leave me comments on Twitter, DM, or follow: www.twitter.com/waseefakhtar âď¸
If you enjoyed this, you might also be interested in other stories that I recently published:
Android MotionLayout: Creating the Twitter splash screen in the simplest way possible |