Sunday, December 22, 2013

How to create your own Maven Repository in Git hub

First you need to have a repository created in Github, I assume you already have it and I will use maven-repo as the repository name as an example.

Clone the empty repository to your home directory or what ever location you prefer.

 git clone https://github.com/Harsha/maven-repo.git maven-repo  

my local repository path is /home/harsha/maven-repo

Inside your project which you would like to share jar files in maven-repo define maven deployment plugin as below in pom.xml.

 <distributionManagement>  
  <repository>  
   <id>internal.repo</id>  
   <name>Internal Repository</name>  
   <url>${internal.repo.path}</url>  
  </repository>  
 </distributionManagement>  


Then you need to define below properties for the jar file. Important point is
 <internal.repo.path>  
which should points to your local repository which you get cloned above.

 <groupId>com.harsha.company.project</groupId>  
 <artifactId>module-name</artifactId>  
 <packaging>jar</packaging>
 <version>1.0</version>
 <properties>  
           <internal.repo.path>file:/home/harsha/maven-repo/</internal.repo.path>  
 </properties>  

Now you can do
 mvn deploy  
inside your project. It will create all the artifacts and publish to the local maven repository which you get cloned above.

Now you can see all the artifacts are published in your local repository - /home/harsha/maven-repo. Just commit these changes and pushed to the git-hub.

How to download published jars from the repository.

Use below repository to download dependencies from your repository.

 <repositories>  
           <repository>  
                <id>maven-repo</id>  
                <url>https://github.com/Harsha/maven-repo/raw/master</url>  
           </repository>  
 </repositories>  


 <dependency>  
      <groupId>com.harsha.company.project</groupId>  
      <artifactId>module-name</artifactId>  
      <version>1.0</version>  
 </dependency>  


You have successfully created your own repository from which others can download dependecies etc.



2. If it is a Play project
======================

To publish your project jar files inside Maven-repo issue the below command first inside your play application. This is not the best way to do it, but it is a pretty smart hack.

play publish-local

This will publish your jars into the local play repository located inside your play installation.
Go to that directory and find the jar file which you need to publish into the maven-repo.

Install this jar file manually into your local maven repository using the below command.

mvn install:install-file -Dfile= -DgroupId=com.redmart.sso.integration -DartifactId=sso-integration -Dversion=1.0 -Dpackaging=jar



This will install your jar into .m2/repository. Go to that directory and copy the com directory into your local maven-repo which you get cloned from Github. If you already have many artifacts inside com directory, make sure only to copy redmart directory.

You are done and just commit and push your changes in maven-repo

To make that jars as a dependency inside your play project add below lines to your Build.scala



i.e
” %  “” % “
"com.redmart.sso.integration"   %  "sso-integration" % "1.0"

Add the below repository.

resolvers += "maven-repo" at "https://github.com/Redmart/maven-repo/raw/master/",



You are done !


No comments: