前言:

开始用maven管理java项目后,突然发现自己写了一些通用的项目想要被别的项目依赖是件很麻烦的事。公司里项目依赖可以直接有maven仓库,但个人项目呢?

github 再次显示其威力了,example:https://github.com/Lhfcws/mvn-repo/

网上找了很多博客教程,都不全面,决定自己搭建成功了就分享一个。


假设我有个项目名叫 pyara ,我的个人repo名叫 mvn-repo 。(其实就是真的,不用假设。。。)


Repo:

建立mvn-repo的文件结构

 mkdir -p mvn-repo/releases
mkdir -p mvn-repo/snapshots

在github上也同样建立一个remote的项目 mvn-repo。(github不会用的请先学习github)

repo这边基本就完成了


Local Settings:

打开或新建(如果没有的话) ~/.m2/settings.xml ,~/.m2/ 为本机maven下载依赖的路径,里面存放着dependency的jar包。

添加一下内容:

 <settings xmlns=" http://maven.apache.org/POM/4.0.0 " xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd ">
<servers>
<server>
<id>github</id>
<username>USERNAME</username>
<password>PASSWORD</password>
</server>
</servers>
</settings>

USERNAME 和 PASSWORD 即你的github的账户密码。保存后将settings.xml设置权限,防止你的密码泄漏。

 sudo chmod  ~/.m2/settings.xml

Project pom.xml:

这个是最重要的一步,此处假设你已有一个可以 mvn package 成功的pom.xml 。

github设置,可以帮你自动commit。

  <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
</properties>
 <plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.9</version>
<configuration>
<message>Maven artifacts for ${project.version}</message> <!-- git commit message -->
<noJekyll>true</noJekyll> <!-- disable webpage processing -->
<outputDirectory>/home/lhfcws/coding/workspace/mvn-repo</outputDirectory> <!-- matches distribution management repository url above -->
<branch>refs/heads/mvn-repo</branch> <!-- remote branch name -->
<includes>
<include>
**/*
</include>
</includes>
<repositoryName>pyara</repositoryName> <!-- github repo name -->
<repositoryOwner>lhfcws</repositoryOwner> <!-- github username -->
</configuration>
<executions>
<!-- run site-maven-plugin's 'site' target as part of the build's normal 'deploy' phase -->
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>

repo设置:

distributionManagement 指定 deploy 的 destination ,切记url里需要指定协议,否则Wagon无法支持。

repositories 指定查找dependencies 的地方,repositories可以根据自己需求改变路径。

    <distributionManagement>
<repository>
<id>releases</id>
<!-- <url>https://github.com/Lhfcws/mvn-repo/raw/master/releases</url> -->
<url>file://${project.basedir}/../mvn-repo/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>file://${project.basedir}/../mvn-repo/snapshots</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>lhfcws-mvn-repo</id>
<url>https://raw.github.com/lhfcws/mvn-repo/master/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

添加 Wagon 支持:

Wagon 插件可以帮助deploy时的文件传输(http, scp, scm, file, ftp等)。

 <extensions>
<extension>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<groupId>org.apache.maven.wagon</groupId>
<version>2.2</version>
</extension>
</extensions>

如果deploy时抛错类似下面:

Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project pyara: Failed to deploy artifacts/metadata: No connector available to access repository snapshots (/home/lhfcws/coding/workspace/pyara/../mvn-repo/snapshots) of type default using the available factories WagonRepositoryConnectorFactory

基本不是没有添加Wagon extension,就是没有指定协议或协议不支持。

SCM 支持:

可选,应该是可以不加的,除非指定要下载代码。

 <scm>
<connection>scm:git:git://github.com/Lhfcws/pyara.git</connection>
<url>scm:git:git://github.com/Lhfcws/pyara.git</url>
<developerConnection>scm:git:git://github.com/Lhfcws/pyara.git</developerConnection>
</scm>


至此,尝试一下mvn deploy,见证奇迹的时刻。

最后deploy成功后还需要把本地仓库的mvn-repo提交到github,over。

Make github as your personal maven repository的更多相关文章

  1. 安装java memcached client到本地maven repository

    由于目前java memcached client没有官方的maven repository可供使用,因此使用时需要手动将其安装到本地repository.java memcached client的 ...

  2. 【Maven】IKAnalyzer 在Maven Repository不存在

    1.在mvnrepository里面找IKAnalyzer,这个中文分词包,一直没有找到,找到github,发现是一个国人写的. http://mvnrepository.com/search?q=I ...

  3. 国内可用maven repository 配置

    国内可用maven repository 配置 发表于2016/1/4 23:08:04  10235人阅读 分类: maven 鉴于一些原因,从maven中央仓库download依赖包时,被各种折磨 ...

  4. 如何利用Maven Repository下载开源软件jar包

    1.打开Maven Repository 网站:https://mvnrepository.com/ 2.输入需要寻找的jar包名称,比如mybatis,点击search,一般第一个就是 3.点击选择 ...

  5. maven repository 配置

    eclipse maven 配置修改: maven repository 配置 http://blog.csdn.net/joewolf/article/details/4876604 Maven缺省 ...

  6. maven安装,使用说明,及maven Repository如何使用.

    maven的使用方法总结一下 1.首先去apache官网下载maven, http://maven.apache.org/download.cgi2.如果是windows系统,选择 apache-ma ...

  7. Maven - Repository(存储库)

    版权所有,未经授权,禁止转载 章节 Maven – 简介 Maven – 工作原理 Maven – Repository(存储库) Maven – pom.xml 文件 Maven – 依赖管理 Ma ...

  8. 将自定义jar包上传github并制作成maven仓库

    参照:https://www.jianshu.com/p/98a141701cc7 第一阶段 :配置github 1.创建mvn-repo分支     首先在你的github上创建一个maven-re ...

  9. Spring Boot从入门到精通(二)配置GitHub并上传Maven项目

    简单介绍一下GitHub,它是一个面向开源及私有软件项目的托管平台,因为只支持git作为唯一的版本库格式进行托管,故名GitHub. GitHub于2008年4月10日正式上线,除了Git代码仓库托管 ...

随机推荐

  1. 群里分享的react的收藏一下!今日周末,改了个表单验证然后无所事事了!

    今日周末,改了个表单验证然后无所事事了,然后把昨天群里分享的react的收藏一下尽管现在还在研究angular和nodeJs毕竟刚刚开始用有点不熟...没准以后会研究一下react毕竟看着下面这张图还 ...

  2. Tomcat SSL的安装及配置中遇到问题

    配置tomcat服务器利用SSL进行加密. 一.生成密钥库 具体生成方式就不讲了,tomcat支持的keystore的格式有JKS,PKCS11和PKCS12 JKS是jdk /bin目录下keyto ...

  3. iOS中常用属性的关键字的使用说明

    属性关键字的作用 现在我们iOS开发中,基本都是使用ARC(自动引用计数)技术,来编写我们的代码.因此在属性property中我们经常使用的关键字有strong,weak,assign,copy,no ...

  4. WindowsPhone8.1RT建立空白应用挂起没反应的解决方案

    wp8.1下, 建立空白应用后遇到的问题:想要实现保存.提取数据都无法成功 在退出程序后无法进入到OnNavigatedFrom()中去. 网上说要手动的Invoke OnSuspending事件. ...

  5. shell--2.shell数组

    shell 数组 (1)定义数组 shell中,用括号表示数组,数组元素用空格分开,定义数组的一般形式 arrt_name=(val1 val2 val3) 或者 arry_name=(val1 va ...

  6. https://zeroc.com/index.html

    https://zeroc.com/index.html http://blog.shutupandcode.net/?p=1085

  7. php实验四

    实验四 1.创建一个Person类,Person中包含三个属性name,age,wealth,分别设置为public,private,protected,再定义Person类的子类Student. 2 ...

  8. .Net全景视图

    http://www.oneapm.com/ai/dotnet.html OneOneAPM 助您轻松锁定 .NET 应用性能瓶颈,通过强大的 Trace 记录逐层分析,直至锁定行级问题代码.以用户角 ...

  9. filedownload

    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-app PUBLIC "-/ ...

  10. POJ 1780 Code(有向图的欧拉通路)

    输入n(1<=n<=6),输出长度为10^n + n -1 的字符串答案. 其中,字符串以每n个为一组,使得所有组都互不相同,且输出的字符串要求字典序最小. 显然a[01...(n-1)] ...