Saturday, June 23, 2012

Maven Repositories on GitHub - By http://chkal.blogspot.com




http://chkal.blogspot.com/2010/09/maven-repositories-on-github.html

https://github.com/chkal/jsf-maven-util/tree/gh-pages/repository

http://chkal.github.com/jsf-maven-util/repository/

https://help.github.com/articles/user-organization-and-project-pages


The basic idea of hosting Maven repositories on GitHub is to use GitHub Pages. This GitHub feature offers a simple but powerful way for creating and hosting web sites on their infrastructure. Fortunately this is all we need to create Maven repositories.



1
2
3
4
5
$ 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



The first step is to create a separate clone of your GitHub repository in a directory next to your primary local repository:


The GitHub Pages web site must be created as a branch named gh-pages in your repository. So lets create this branch and empty it. Refer to the GitHub Pages Manual if you are interested in the exact meaning of these commands.



1
2
3
$ git symbolic-ref HEAD refs/heads/gh-pages
$ rm .git/index
$ git clean -fdx


We will place the Maven repository in a subdirectory of this new branch:



1
$ mkdir repository




We also want to have a pretty directory listing. Unfortunately GitHub Pages doesn't have native support for this. So we will create our own directory listing with a simple bash script.
Create a file named update-directory-index.sh in the root of the new branch (next to therepository directory). This script will walk recursively into the repository directory and createindex.html files in each subdirectory. Please be careful when using this script as it overwrites all exiting index.html files it finds.




1
2
3
4
5
6
7
8
9
#!/bin/bash
 
for DIR in $(find ./repository -type d); do
  (
    echo -e "\n\n

Directory listing

\n
\n
"
    ls -1pa "${DIR}" | grep -v "^\./$" | grep -v "^index\.html$" | awk '{ printf "%s\n",$1,$1 }'
    echo -e "\n\n"
  ) > "${DIR}/index.html"
done




Congratulations! Your repository is ready. Now you will have to modify thedistributionManagement section of your pom.xml to let Maven deploy your artifacts to the new repository. Go back to your primary repository clone and edit your pom.xml:



1
2
3
4
5
6
<distributionManagement>
  <repository>
    <id>gh-pagesid>
    <url>file:///${basedir}/../jsf-maven-util-pages/repository/url>
  repository>
distributionManagement>


Now you are ready to deploy your first artifact to the repository:



1
$ mvn -DperformRelease=true clean deploy


You will see that Maven copies the artifacts to your local checkout of the GitHub Pages branch. After Maven has finished you'll have to update the directory listings, commit the changes made to the repository and push them to GitHub:



1
2
3
4
5
$ cd ../jsf-maven-util-pages/
$ ./update-directory-index.sh
$ git add -A
$ git commit -m "Deployed my first artifact to GitHub"
$ git push origin gh-pages



Now let's check the result. Please note that the first publish may take some time to appear on the web server.
Looks great, doesn't it? :-)
If you want to use your repository in another project, just add the following repository entry to the pom.xml:
?



1
2
3
4
5
<repository>
  <id>jsf-maven-util-repoid>
  <name>jsf-maven-util repository on GitHubname>
  <url>http://chkal.github.com/jsf-maven-util/repository/url>
repository>







No comments: