Using Github as Maven Repository

Yet another post about using Github as Maven Repositorye

Using GitHub as a Maven Repository

Introduction Maven and Github

Maven is a build automation tool used primarily for Java projects.

Maven addresses two aspects of building software: first, it describes how software is built, and second, it describes its dependencies. Unlike earlier tools like Apache Ant, it uses conventions for the build procedure, and only exceptions need to be written down. An XML file describes the software project being built, its dependencies on other external modules and components, the build order, directories, and required plug-ins. It comes with pre-defined targets for performing certain well-defined tasks such as compilation of code and its packaging.

GitHub is a web-based hosting service for version control using git. It is mostly used for computer code. It offers all of the distributed version control and source code management (SCM) functionality of Git as well as adding its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, and wikis for every project.

GitHub offers plans for both private repositories and free accounts which are commonly used to host open-source software projects. As of April 2017, GitHub reports having almost 20 million users and 57 million repositories, making it the largest host of source code in the world.

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">

Then we should run mvn deploy

Pushing Artifact to GitHub

Let’s create an empty GitHub repository. Let’s suppose its URL is (for example):


Now clone this repository to your system:

>test-repo git clone https://github.com/usename/maven.git

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

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.

comments powered by Disqus