Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joutvhu/publish-maven-guide

How to publish Java library to Maven Repository
https://github.com/joutvhu/publish-maven-guide

guide maven publish training

Last synced: 4 days ago
JSON representation

How to publish Java library to Maven Repository

Awesome Lists containing this project

README

        

# Publish Java library to Maven Repository

## Create a JIRA Account and Request a Ticket

First, you will need to have a [Sonatype JIRA](https://issues.sonatype.org) account to open a new ticket to request your access to publish your artifact.

Then, create a JIRA ticket to fill your information.

![alt text](./doc/create-ticket.png)

You have to fill your domain name or use your github domain into Group Id field. Then prove ownership by adding a text record to your domain or create a repository with the specified name.

## Create a GPG key

You will also need a private key to sign the artifact.

- [Use Git](https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key)

- [Use Tool](https://www.openpgp.org/software/)

Publish your GPG certificate to key servers. Recommended: https://keyserver.ubuntu.com

## Save your Environment Variables

You can safely store your credentials into the .m2/settings.xml file in your
user's home directory.

```xml



ossrh
{ username }
{ password }




ossrh

true


gpg
{ gpg-key }
{ gpg-passphrase }


```

## Set Up Maven in the Project

```xml
4.0.0
com.github.joutvhu
test
1.0-SNAPSHOT
test
Test Lib
https://github.com/joutvhu/test

Giao Ho
https://github.com/joutvhu


MIT License
https://github.com/joutvhu/test/blob/master/LICENSE


joutvhu
Giao Ho
[email protected]

scm:git:[email protected]:joutvhu/test.git
scm:git:[email protected]:joutvhu/test.git
https://github.com/joutvhu/test

Github Issue
https://github.com/joutvhu/test/issues

```

## Build Config

This will add the configuration for the build tag.

Add the following maven plugins:

```xml



org.apache.maven.plugins
maven-source-plugin
3.2.1


attach-sources

jar-no-fork





org.apache.maven.plugins
maven-javadoc-plugin
3.4.1


attach-javadocs

jar





${java.home}/bin/javadoc




org.apache.maven.plugins
maven-surefire-plugin
2.22.2


org.sonatype.plugins
nexus-staging-maven-plugin
1.6.13
true

ossrh
https://oss.sonatype.org/
true



org.apache.maven.plugins
maven-gpg-plugin
3.0.1


sign-artifacts
verify

sign




```

## Distribution Management Config

Add this child to the project's root:

```xml


ossrh
https://oss.sonatype.org/content/repositories/snapshots


ossrh
https://oss.sonatype.org/service/local/staging/deploy/maven2

```

## Uploading to Sonatype Repository

Add "-SNAPSHOT" if you will deploy to the snapshot repository. For example:

```
1.0.0-SNAPSHOT
```
or else:
```
1.0.0
```

Then run the following command to upload your library.

```sh
mvn deploy
```

Now go to https://oss.sonatype.org and login to check result.

![alt text](./doc/result.png)