前言:

开始用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. 试图加载格式不正确的程序。 (异常来自HRESULT:0x8007000B)

    异常来自HRESULT:0x8007000B   缘由:在64位操作系统下IIS发布32位的项目,报“项目依赖的dll无法读取,试图加载格式不正确的程序”错误. 原因:程序集之间的通讯要么全是64位环 ...

  2. PropertiesFactoryBean PropertyPlaceholderConfigurer 区别

    正如 stackoverflow上说的,PropertiesFactoryBean 是PropertiesLoaderSupport 直接的实现类, 专门用来管理properties文件的工厂bean ...

  3. Swift3.0P1 语法指南——控制流

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  4. UIStackView

    既要温故又要知新...温故而知新,我懂. 在Cocoachina上看到了,UIStackView. 没用过额,试iOS9的新特性.一研究,妈的还挺眼熟.一想,这不和Android上的线性布局一样么.. ...

  5. C#导出涉及行列合并的复杂的Excel数据

    一.导出数据格式 二.实现代码 /// <summary> /// 导出经费统计excel表格 /// </summary> /// <param name=" ...

  6. js中数组连接concat()

    数组连接concat() concat() 方法用于连接两个或多个数组.此方法返回一个新数组,不改变原来的数组. 语法 arrayObject.concat(array1,array2,...,arr ...

  7. NTC 热敏电阻温度计算公式

    Rt = R *EXP(B*(1/T1-1/T2))这里T1和T2指的是K度即开尔文温度,K度=273.15(绝对温度)+摄氏度:其中T2=(273.15+25)Rt 是热敏电阻在T1温度下的阻值: ...

  8. [Android Pro] ScrollView使用fillViewport设置高度为MatchParent

    reference to : http://blog.csdn.net/u012975705/article/details/49275001 之前遇到一问题,就是当使用ScrollView时,Scr ...

  9. Cycles渲染研究测试效果图

    从左到右:.贴图镂空透明  2.纹理半透明  3.纹理  4.材质半透明  5.材质 输入输出节点信息如下: ############################################# ...

  10. Oracle Database 11g Release 2(11.2.0.3.0) RAC On Redhat Linux 5.8 Using Vmware Workstation 9.0

    一,简介 二,配置虚拟机 1,创建虚拟机 (1)添加三块儿网卡:   主节点 二节点 eth0:    公网  192.168.1.20/24   NAT eth0:    公网  192.168.1 ...