Create your own github Maven repository

Maven works with repositories and, when using github to share projects, it does make sense to have a single place to share dependencies that are not yet available in a public place.

Recently I’ve been exploring the beauties of Vert.X IO and since then I’ve been placing all source and maven projects in github.

The Vert.X IO Maven project template initially included a local repository in it but, and as one starts working on other Vert.X IO projects, the amount of replicated jars start being quite visible.

It happens that the easy solution is to make use of github to share these jars.

Step 1: Create root directory for maven repository

Assuming that you have a github account and a cloned github repository then your first step is to create a new directory for the maven repository (e.g. maven/repository).

mkdir maven-repo
cd maven-repo
mkdir repository

Step2: Add jars to your new maven repository

Adding a jar to a local repo is quite easy. For example, the following command adds the to the local repository.

mvn install:install-file -DgroupId=com.vertx -DartifactId=vertx-core -Dversion=1.2.2 -Dfile=PATH_TO_VERTX_JARS/ -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repository

Since Vert.X has been releasing versions like a machine gun releases bullets, I’ve decided to create a small script to automate the process.


LIBS=(core lang-groovy lang-java lang-jruby lang-jython lang-rhino platform testframework)

for NAME in ${LIBS[*]}
	printf "Adding to local repository...\n" $NAME $VERSION
	mvn install:install-file -DgroupId=com.vertx -DartifactId=vertx-$NAME -Dversion=$VERSION -Dfile=$PATH_TO_VERTX_JARS/vertx-$NAME-$ -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repository

Once you have finished adding jars to the maven repository simply commit and push your changes to github.

Step 3: Point the Maven project POM to the github repository

This was the trickiest part of it. It happens that the URL for my github maven repo is the following:

And that will not work. If you do it you’ll noticed that your maven repository will be filled with the correct structure but the files will contain basic HTML. Obviously… your project will have a hard time to compile against HTML files with a ‘.jar’ extension. 🙂

Instead, one has to use the RAW version of the github repo. Play close attention for the following URL differences:

Blob URL (returns HTML):

Raw URL (returns the real file):

Based on this, the project POM will then have to include a repository entry to the RAW link as shown below.


About CrazyPenguin

Software Engineer
This entry was posted in github, maven, Vert.X IO. Bookmark the permalink.

2 Responses to Create your own github Maven repository

  1. Pingback: Hosting Maven Repository for third-party jars on Git (Bitbucket/Github) | Active Intelligence

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s