Using gitub as a maven repository

If you shun the work that comes with uploading JARs to the central maven repository, here’s a simple way to host your own maven repository on github [1].

I’m copying the bare essentials from Christian Kaltepoth’s article, you should read it for the details:

Setting up

—-

$ pwd
/home/ck/workspace/jsf-maven-util
$ cd
..
$ git clone git@github
.com:chkal/jsf-maven-util.git jsf-maven-util-pages
$ cd jsf
-maven-util-pages
 
$ git symbolic-ref HEAD refs/heads/gh-pages
$ rm
.git/index
$ git clean
-fdx


$ mkdir repository

In the pom.xml:



gh-pages</id&gt
file:///${basedir}/../jsf-maven-util-pages/repository/

 
 

Update 2014.08.27I came across this post [2] which uses the maven-site-plugin to simplify deployment. This post uses a dedicated git branch as a maven repository, which seems cleaner to me. For continuity I’m repeating the instructions with modifications to use the gh-pages branch:

1. Add your github account to ~/.m2/settings.xml:


 
   
      github
      your-github-user-name
      github-password
   
 

 

Then some work in the pom.xml:


  
   github
 
<distributionManagement>
    <repository>
        <id>internal.repo</id>
        <name>Temporary Staging Repository</name>
        <url>file://${project.build.directory}/mvn-repo</url>
    </repository>
</distributionManagement>
 
<build>
 <plugins>
    <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>2.8.1</version>
        <configuration>
               <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
        </configuration>
    </plugin>
   
        com.github.github
        site-maven-plugin
        0.9
       
           
            Maven artifacts for ${project.version}
           
            true
           
            ${project.build.directory}/mvn-repo
           
            refs/heads/gh-pages
            <!-- If you remove this then the old artifact will be removed and new
                one will replace. But with the merge tag you can just release by changing
                the version -->
            true
           
                **/*
           
           
            YOUR-GITHUB-REPOSITORY-NAME
           
            YOUR-GITHUB-USER
        
        
            
                
                     site
                
                 deploy
            
        
   
 
</plugins>
</build>

A simple mvn deploy will build the project and upload the artifacts.

Resources

[1] Maven Repositories on GitHub
http://blog.kaltepoth.de/posts/2010/09/06/github-maven-repositories.html

[2] How to create simple maven repository on GitHub
http://malalanayake.wordpress.com/2014/03/10/create-simple-maven-repository-on-github/

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