Over a million developers have joined DZone.

Using GitHub as a Maven Repository

DZone's Guide to

Using GitHub as a Maven Repository

This exercise shows how you can use GitHub as a Maven repository — it's not the professional way to do things, but it's fun just to learn how it works!

· DevOps Zone ·
Free Resource

Easily enforce open source policies in real time and reduce MTTRs from six weeks to six seconds with the Sonatype Nexus Platform. See for yourself - Free Vulnerability Scanner. 


In this short article, I'm going to explain how to use GitHub as a Maven Repository. This is a cheap alternative to using an artifactory like Nexus, JFrog, etc. 


This is not the recommended way to host a Maven repository. This tutorial is an exercise for learning purposes only, not the proper way of hosting a repository. You must go with Nexus, JFrog, etc. for the professional experience.

Maven Project

Let's create a simple Maven project. We will export this project as artifact so that it can be used in other projects. This artifact will be pushed to GitHub. Here is the pom.xml of the project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

The most important part of the pom.xml is:


The URL can be anything valid. Now execute the following command:

 mvn deploy 

It will generate the artifact as shown in the below diagram:

Image title

Pushing the Artifact to GitHub

Let's create an empty GitHub repository. Let's suppose its URL is https://github.com/anupamgogoi0907/artifacts.git.

Now clone this repository to your system:

>test-repo git clone https://github.com/anupamgogoi0907/artifacts.git

Copy the artifact generated under the mvn-repo folder (in the previous step), and then push it to the repository.

It should look something like this in your GitHub account:

Image title

At this stage, we have pushed our artifact to our GitHub repository. Now let's try to make use of it.

Using the GitHub Artifact

Now let us create a new Maven project and use the artifact we pushed to GitHub in the previous step.

Add the following repository declaration in the pom.xml.


And that's it. Execute the  mvn compile command and the artifact will be downloaded from the repository.


In this article, I have shown how easy it is to use the GitHub as your repository manager. Remember, this is just an exercise to show how it can be done, and isn't the professional way to host a repository.

Automate open source governance at scale across the entire software supply chain with the Nexus Platform. Learn more.

maven 3.5.0 ,maven ,github ,devops ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}