Build a personal Maven repository with GitHub

Source: Internet
Author: User
Tags sha1

Original source: Hengyunabc

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:

    1. Deploy to local Directory
    2. Submit the local directory to the Gtihub
    3. 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, deploy the project to the /home/hengyunabc/code/maven-repo/repository/ directory:

123456 <distributionManagement>    <repository>      <id>hengyunabc-mvn-repo</id>      <url>file:/home/hengyunabc/code/maven-repo/repository/</url>    </repository>  </distributionManagement>

The command line is:

1 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

Deploy the project to a local directory home/hengyunabc/code/maven-repo/repository , and submit the directory to GitHub below.

Create a new project on GitHub, and then home/hengyunabc/code/maven-repo submit the next file to the Gtihub.

123456 cd /home/hengyunabc/code/maven-repo/git initgit add repository/*git commit -m ‘deploy xxx‘git remote add origin git@github.com: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 raw.githubusercontent.com this domain name for raw file downloads. So using this Maven repository, just add in the Pom.xml:

123456 <repositories>        <repository>            <id>hengyunabc-maven-repo</id>            <url>https://raw.githubusercontent.com/hengyunabc/maven-repo/master/repository</url>        </repository>    </repositories>
catalog view and search

It is worth noting that for security reasons, GitHub has the raw file download and the original GitHub domain name is separate, and raw.githubusercontent.com this domain name is not supported directory browsing. So, if you want to browse the file directory, or search, you can go directly to the GitHub domain repository to see.

For example, this file mybatis-ehcache-spring-0.0.1-20150804.095005-1.jar :

The browser address is:

https://github.com/hengyunabc/maven-repo/blob/master/repository/io/github/hengyunabc/mybatis-ehcache-spring/ 0.0.1-snapshot/mybatis-ehcache-spring-0.0.1-20150804.095005-1.jar

Its Maven repository URL is:

https://raw.githubusercontent.com/hengyunabc/maven-repo/master/repository/io/github/hengyunabc/ Mybatis-ehcache-spring/0.0.1-snapshot/mybatis-ehcache-spring-0.0.1-20150804.095005-1.jar

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

123 maven-metadata.xmlmaven-metadata.xml.md5maven-metadata.xml.sha1

maven-metadata.xmlThe last deploy version and time are recorded.

1234567891011121314 <?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 the request first, and maven-metadata.xml 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.xmlFiles 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:

123456 <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. QQ Technology Group 290551701

Build a personal Maven repository with GitHub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.