Publishing Java SpringBoot Library in JitPack

October 9th, 2020 by

Pre-requisites

A Github account and a new project repository which will contain the codes of our library.

Jitpack Account where we will be publishing our library.

 

Create the Library

The first thing you need to do is to create your library project. For this tutorial, we are going to create a Spring Boot Library, and later add it as a dependency on other projects that we will be working on.

Go to https://start.spring.io/ and create a basic SpringBoot Project. There are ways to create a Spring Boot Project, if you are interested, you may check out our tutorial on how to create SpringBoot using Intellij Ultimate or maven.

 

Preparing our Library

We need to delete unnecessary files in our library. I have deleted the AwesomeLibraryApplication and the equivalent test class. You may also delete the application.properties as externalizing your configuration files is best practice (we won’t do config externalization here).

All Categories

 

Delete the following lines of code in your pom.xml

 

For this tutorial, I will be adding a method that gets the most frequent integer out of the array.

CustomArrayUtil.java

Testing

Check if your library will still create a jar file. Run “mvn install”. It should create a jar file in your target folder.

 

Push your Codes in Github.

After completing the steps above, we need to create a new repository and push our code to that repository in Github. If you do not know how to do that, you may check this tutorial.

 

Publishing your Code

Login to https://jitpack.io/. You may use your Github account. Paste the repository URL in the lookup field.

Choose which commit you would like to get. If the build is successful, you’ll see a green document icon. Click it and you can see the build logs.

Importing Library in your Project

Below, you can see how to import your library on different dependency management tools. Open your new Springboot application and add the library as a dependency.

I added the following codes in my pom.xml

(under <dependencies> tag)

 

 

Output

We were able to import the CustomArrayUtil from our library after adding the dependency.

Spread the love


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *