Origin
Before I saw an open source project using GitHub as a MAVEN repository, I wondered if I could make one. Studied the next, recorded.
In simple terms, there are three steps:
- Deploy to local Directory
- Submit the local directory to the Gtihub
- Configure GitHub address as warehouse address
Configure local file Maven repository to deploy locally
MAVEN can deploy to remote servers via HTTP, FTP, SSH, etc., or to a local file system. For example:
<distributionManagement> <repository> <id>hengyunabc-mvn-repo</id> <url>file:/home/hengyunabc/code/maven-repo/repository/</url> </repository> </distributionManagement>
The command line is:
mvn deploy -DaltDeploymentRepository=hengyunabc-mvn-repo::default::file:/home/hengyunabc/code/maven-repo/repository/
It is recommended to deploy using the command line to avoid explicit configuration in the project.
https://maven.apache.org/plugins/maven-deploy-plugin/
Https://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html
Submit a local repository on GitHub
The item is posted to the local directory home/hengyunabc/code/maven-repo/repository, and the directory is submitted to GitHub.
Create a new project on GitHub, and then submit the files under Home/hengyunabc/code/maven-repo to Gtihub.
cd‘deploy xxx‘git remote add origin [email protected]:hengyunabc/maven-repo.gitgit push origin master
The final effect can be referred to my personal repository:
Https://github.com/hengyunabc/maven-repo
Use of the GitHub Maven repository
Because GitHub uses the raw.githubusercontent.com domain for raw file downloads. So using this Maven repository, just add in the Pom.xml:
<repositories> <repository> <id>hengyunabc-maven-repo</id> <url>https://raw.githubusercontent.com/hengyunabc/maven-repo/master/repository</url> </repository> </repositories>
The mechanism of MAVEN warehouse work
Here are some of the principles of MAVEN warehouse work. A typical Maven dependency will have these three files:
Https://github.com/hengyunabc/maven-repo/tree/master/repository/io/github/hengyunabc/mybatis-ehcache-spring/0.0.1-SNAPSHOT
maven-metadata.xmlmaven-metadata.xml.md5maven-metadata.xml.sha1
The last deploy version and time are recorded in the Maven-metadata.xml.
<?xml version= "1.0" encoding= "UTF-8"?><metadata modelversion="1.1.0"> <groupId>Io.github.hengyunabc</groupId> <artifactid>Mybatis-ehcache-spring</artifactid> <version>0.0.1-snapshot</version> <versioning> <snapshot> <timestamp>20150804.095005</timestamp> <buildnumber>1</BuildNumber> </Snapshot> <lastupdated>20150804095005</lastupdated> </versioning></metadata>
Where MD5, the SHA1 checksum file is used to guarantee the integrity of this meta file.
When Maven Yi a project, it tries to request Maven-metadata.xml first, and if it does not, it tries to request the jar file directly, and when the jar file is downloaded, it also attempts to download the JAR's MD5, SHA1 file.
Maven-metadata.xml files are important, and if you do not have this file to indicate the latest jar version, even if the jar in the remote repository is updated, the local Maven codec Yi uses the-u parameter and does not pull up to the latest jar!
So it's not easy to put the jar bag on GitHub and it's done, so be sure to deploy it locally, generate the Maven-metadata.xml file, and upload it to GitHub.
Reference: http://maven.apache.org/ref/3.2.2/maven-repository-metadata/repository-metadata.html
MAVEN's Warehouse relationship
Https://maven.apache.org/repository/index.html
Configure the use of a local warehouse
To use the local file repository, configure it in the pom.xml of the project, such as:
<repositories> <repository> <id>hengyunabc-maven-repo</id> <url>file:/home/hengyunabc/code/maven-repo/repository/</url> </repository> </repositories>
Precautions
Maven Repository does not have a priority configuration, and it cannot configure repository for some dependencies alone. So if the project is configured with multiple repository, the first time you compile Yi, you will attempt to download dependencies in turn. If not found, try the next, the whole process will be very long.
So as many dependencies as possible to put in the same warehouse, not every project has a own warehouse.
Reference
http://stackoverflow.com/questions/14013644/hosting-a-maven-repository-on-github/14013645#14013645
http://cemerick.com/2010/08/24/hosting-maven-repos-on-github/
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Build a personal Maven repository with GitHub