Use github to build a personal maven repository, githubmaven

Source: Internet
Author: User

Use github to build a personal maven repository, githubmaven

Source: hengyunabc

Origin

Previously, I saw an open-source project using github as a maven repository, and I thought I would do it myself. Under research, record.

To put it simply, there are three steps:

Configure local file maven repository deploy to local

Maven can use deploy such as http, ftp, and ssh to connect to a remote server, or deploy to a local file system.

For example, deploy the project/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/

We recommend that you use command line deploy 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 the local repository to github

Deploy the project to the local directory.home/hengyunabc/code/maven-repo/repositoryAnd submit the directory to github.

Create a new project on Github andhome/hengyunabc/code/maven-repoAll files under are submitted to 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

For the final result, refer to my personal Repository:

Https://github.com/hengyunabc/maven-repo

Use of github maven Repository

Because github usesraw.githubusercontent.comThis domain name is used for raw file download. To use this maven repository, you only need to add the following in pom. xml:

123456 <repositories>        <repository>            <id>hengyunabc-maven-repo</id>            <url>https://raw.githubusercontent.com/hengyunabc/maven-repo/master/repository</url>        </repository>    </repositories>
Directory viewing and searching

It is worth noting that, for security reasons, github separates the raw file download from the original github domain name.raw.githubusercontent.comThis domain name does not support directory browsing. Therefore, if you want to browse the file directory or search for it, you can directly view it in the repository under the github domain name.

For example, this filemybatis-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

Working Mechanism of maven Repository

The following describes how maven repositories work. A typical maven dependency includes the following 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.xmlIt records the last deploy version and time.

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>

The md5 and sha1 verification files are used to ensure the integrity of the meta File.

When maven is compiling a development project, it first tries to requestmaven-metadata.xmlIf not found, the system will directly request the jar file. When downloading the jar file, it will also try to download the md5 and sha1 files of the jar.

maven-metadata.xmlFile is very important. If this file is not used to specify the latest jar version, even if the jar version in the remote repository is updated, the-U parameter is used during local maven compilation, it won't pull the latest jar!

Therefore, you cannot simply put the jar package on github. You must first Deploy it locally to generatemaven-metadata.xmlFile and upload it to github.

Reference: http://maven.apache.org/ref/3.2.2/maven-repository-metadata/repository-metadata.html

Maven repository relationship

Https://maven.apache.org/repository/index.html

Configure local repository

To use the local file repository, configure it in the pom. xml file of the project, for example:

123456 <repositories>       <repository>           <id>hengyunabc-maven-repo</id>           <url>file:/home/hengyunabc/code/maven-repo/repository/</url>       </repository>   </repositories>
Notes

The repository of maven does not have a priority configuration and cannot be configured separately for some dependencies. Therefore, if the project is configured with multiple repository, the dependencies will be downloaded in sequence during the first compilation. If it is not found, try the next one, and the entire process will be long.

Therefore, try to store as many dependencies as possible in the same repository. Do not have a repository of your own for each project. QQ technology exchange group 290551701

Related Article

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.