This article describes the idea of using GitHub as a MAVEN repository primarily:
- Create Mvn-repo branch on GitHub project, use Mvn-repo branch as Maven repository
- Configure Pom.xml to use Target/mvn-repo as a temporary MAVEN repository for on-premises deployment
- Use GitHub Site-maven-plugin at deployment to push the local MAVEN repository to the branch Mvn-repo of the GitHub project
Take my project as an example: https://github.com/buzheng/mybatis-pageable
First, configure Pom.xml to tell Maven to deploy artifacts to a temporary directory under target, configured as follows:
<PLUGIN> True<artifactid>maven-deploy-plugin</ Artifactid> true<version>2.8.1 </VERSION> True<CONFIGURATION> truetrue<< Span class= "name" >altdeploymentrepository>internal.repo::d Efault::file://${project.build.directory}/mvn-repo </ALTDEPLOYMENTREPOSITORY> True</CONFIGURATION> </ PLUGIN> |
After the configuration is complete, run the command mvn clean deploy and discover that the MAVEN repository has been deployed to the Target/mvn-repo directory. And then all we have to do is upload that directory to GitHub.
Add GitHub's authorization information to ~/.m2/settings.xml so that GitHub Site-maven-plugin can push files to github with the following configuration information:
<server> <id>github</id> <username> your github account </username> <password> your user name on GitHub </password> </server> |
Add the following configuration to Pom.xml to tell GitHub Site-maven-plugin server information
<properties>true<!--GitHub server corresponds to entry in ~/.m2/settings.xml- true<github.global.server>github</github.global.server> </properties> |
Finally configure the GitHub Site-maven-plugin plugin
<plugin> True<groupid>com.github.github</groupid> True<artifactid>site-maven-plugin</artifactid> True<version>0.9</version> True<configuration> Truetrue<Message>maven artifacts for ${project.version}</message> <!--git commit message -Truetrue<nojekyll>true</nojekyll> <!--disable webpage processing - Truetrue<outputdirectory>${project.build.directory}/mvn-repo</outputdirectory> <!-- Matches distribution Management repository URL above -Truetrue<branch>refs/heads/mvn-repo</branch> <!--remote Branch name -- Truetrue<includes> Truetruetrue<include>**/*</include> Truetrue</includes> Truetrue<repositoryname>mybatis-pageable</repositoryname> <!--GitHub Repo name-- Truetrue<Repositoryowner>buzheng</repositoryowner> <!--GitHub username -- True</configuration> True<executions> Truetrue<!--run site-maven-plugin& #039; s & #039;site& #039; target as part of the build& #039; s normal truetruetrue& #039;d eploy& #039; Phase-->truetrue<execution> Truetruetrue<goals> Truetruetruetrue<goal>site</goal> Truetruetrue</goals> Truetruetrue<phase>deploy</phase> Truetrue</execution> True</executions> </plugin> |
After the configuration is complete, run the command mvn clean deploy, log on to GitHub, discover that the Mvn-repo branch has been created, and upload the local Target/mvn-repo directory.
[INFO] ScanningFor projects ...[INFO] [INFO]------------------------------------------------------------------------[INFO] Building mybatis-pageable 0.1[info]------------------------------------------------------------------------[Info][info]--- Maven-clean-plugin:2.5:clean (Default-clean) @ mybatis-pageable---[INFO] Deleting E:\workspace\mybatis-pageable\ Target[info][info]---maven-resources-plugin:2.6:resources (default-resources) @ mybatis-pageable---[WARNING] Using Platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 0 Resource[info][info]---maven-compiler-plugin:3.1:compile (default-compile) @ mybatis-pageable---[INFO] Changes detected-recompiling the module! [INFO] Compiling 6source files to e:/workspace/mybatis-pageable/target/classes[INFO] [INFO]---maven-resources-plugin:2.6:testresources (default-testresources) @ mybatis-pageable---[INFO] Not copyingTest Resources[INFO] [INFO]---maven-compiler-plugin:3.1:Testcompile (default-testcompile) @ mybatis-pageable---[INFO] Not compilingTest Sources[INFO] [INFO]---maven-surefire-plugin:2.12.4:Test (default-test) @ mybatis-pageable---[INFO] Tests is skipped. [INFO] [INFO]---maven-jar-plugin:2.4:jar (default-jar) @ mybatis-pageable---[info] Building jar:e:/workspace/ Mybatis-pageable/target/mybatis-pageable-0.1.jar[info][info]---maven-install-plugin:2.4:install ( Default-install) @ mybatis-pageable---[INFO] installing e:/workspace/mybatis-pageable/target/ Mybatis-pageable-0.1.jar to C:/USERS/ADAM.MY-PC/.M2/REPOSITORY/ORG/BUZHENG/MYBATIS-PAGEABLE/0.1/ Mybatis-pageable-0.1.jar[info] Installing E:/workspace/mybatis-pageable/pom.xml to C:/Users/Adam.my-pc/.m2/ Repository/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.pom[info][info]---maven-deploy-plugin:2.8.1: Deploy (Default-deploy) @ mybatis-pageable---[INFO] Using Alternate deployment repository Internal.repo::d efault::file ://e:/workspace/mybatis-pageable/target/mvn-repouploading:file://e:/workspace/mybatis-pageable/target/mvn-repo /org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.jaruploaded:file://e:/workspace/mybatis-pageable/target /mvn-repo/org/bUzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.jar (at 1020.2 kb/sec) uploading:file://e:/workspace/ mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.pomuploaded:file://e:/ Workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.pom (4 KB at 907.5 kb/sec) downloading:file://e:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/ maven-metadata.xmluploading:file://e:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/ maven-metadata.xmluploaded:file://e:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/ Maven-metadata.xml (303 B at 147.9 kb/sec) [Info][info]---site-maven-plugin:0.9:site (default) @ mybatis-pageable--- FO] Creating 9 blobs[info] Creating tree with ten blobs Entries[info] Creating commit with SHA-1: ac8a117fa05c3a24f057a68451 9d5edade5d4e64[info] Updating reference Refs/heads/mvn-repo from CF1389181D9559B6926A26E852AA2B605B46DA1E to Ac8a117fa05c3a24f057a684519d5edade5d4e64[info]--------------------------------------------------------- ---------------[INFO] BUILD Success[info]----------------------------------------------------------------------- -[info] Total Time:8.124s[info] finished At:mon June 15:47:54 CST 2014[info] Final Memory:24m/178m[info]------------ ------------------------------------------------------------ |
So far, the project has been deployed on GitHub. If other projects depend on this project, you need to add the following configuration in Pom.xml, and then add the appropriate dependencies.
<repositories>true<repository>truetrue<id> Mybatis-pageable-mvn-repo</id>truetrue<url>https:// raw.github.com/buzheng/mybatis-pageable/mvn-repo/</url>true</ repository> </repositories> |
Complete!
This method is quite handy and requires a few simple configurations to automatically publish the jar package to GitHub.
Reference: Http://stackoverflow.com/questions/14013644/hosting-a-maven-repository-on-github
Use GitHub as a maven repository