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 vertx-core-1.2.2.final.jar to the local repository.

mvn install:install-file -DgroupId=com.vertx -DartifactId=vertx-core -Dversion=1.2.2 -Dfile=PATH_TO_VERTX_JARS/vertx-core-1.2.2.final.jar -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.

#!/bin/bash

PATH_TO_VERTX_JARS=/path/to/vertx/jars
VERSION=1.2.2
LIBS=(core lang-groovy lang-java lang-jruby lang-jython lang-rhino platform testframework)

for NAME in ${LIBS[*]}
do
	printf "Adding vertx-%s-%s.final.jar 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-$VERSION.final.jar -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repository
done

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:

https://github.com/crazyfrozenpenguin/cpenguin_repository/tree/master/maven-repo/repository

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): https://github.com/crazyfrozenpenguin/cpenguin_repository/blob/master/maven-repo/repository/com/vertx/vertx-core/1.2.2/vertx-core-1.2.2.jar

Raw URL (returns the real file): https://github.com/crazyfrozenpenguin/cpenguin_repository/raw/master/maven-repo/repository/com/vertx/vertx-core/1.2.2/vertx-core-1.2.2.jar

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

		<repository>
			<id>crazy-penguin-repository</id>
			<url>https://github.com/crazyfrozenpenguin/cpenguin_repository/raw/master/maven-repo/repository</url>
			<releases>
				<enabled>true</enabled>
			</releases>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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