前言:

开始用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. 汤森路透为何一定要卖掉SCI?

    http://health.sohu.com/20160714/n459331727.shtml

  2. Android网络请求通信之Volley

    一.Volley简介 Volley网络框架是Google公司在2013年发布的一款Android平台上的网络请求通信库.以下是对Volley的简单归纳. Volley的优点: 使网络通信更快.更简单. ...

  3. css3的基本样式

    一.css3字体(@font-face) 二.css3动画 三.css3多列 四.CSS3 outline-offset 属性 五.CSS3 resize 属性

  4. jvm指令调试

    监控GC的工具分为2种:命令行工具和图形工具: 常用的命令行工具有: 注:下面的命令都在JAVA_HOME/bin中,是java自带的命令.如果您发现无法使用,请直接进入Java安装目录调用或者先设置 ...

  5. C和指针 第五章 警告总结

    1.有符号的值得右移位操作是不可移植的 2.移位操作的位数是个负数,是未定义的 3.连续赋值的各个变量的长度 不一,导致变量值截断. #include <stdio.h> int main ...

  6. MiniProfiler(MiniProfiler.EF6监控调试MVC5和EF6的性能)

    git:  https://github.com/MiniProfiler 以前开发Webform的时候可以开启trace来跟踪页面事件,这对于诊断程序的性能是有很大的帮助的,起到事半功倍的作用,今天 ...

  7. 【转】Spring mvc集成ZBUS--轻量级MQ、RPC、服务总线

    本文转自:http://www.cnblogs.com/top15from/p/4899954.html ZBUS = MQ + RPC + PROXY 支持消息队列, 发布订阅, RPC, 代理(T ...

  8. 《C#高级编程(第六版)》泛型学习笔记(一):泛型优点和特性 (转载)

    原文出处:http://www.cnblogs.com/xun126/archive/2011/01/13/1933838.html 泛型是CLR 2.0的一个新特性,在CLR 1.0中,要创建一个灵 ...

  9. 解决NSData转NSString返回nil的问题

    // 字符串转Data NSString *str =@"jesfds"; NSData *data =[str dataUsingEncoding:NSUTF8StringEnc ...

  10. Lamp和Lnmp环境搭建

    一.安装Lamp wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz && tar zxf lnmp1.2-full.tar. ...