前言:

开始用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. 如何让ConfigurationManager打开任意的配置文件

    VisualStudio的配置文件很好很强大,用来保存数据库连接字符串或键值对都非常方便,只需要通过ConfigurationManager的ConnectionStrings或AppSettings ...

  2. PHP控制输出不缓存头

    @header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); @header("Cache-Control: no-cache, ...

  3. Linux C 静态库(.a) 与 动态库(.so) 的详解

    库从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行.库分静态库和动态库两种. 一.静态库和动态库的区别 1.静态函数库 这类库的名字一般是libxxx.a:利用静态函数库编译成的文件比较 ...

  4. Linux进程间通信(八):流套接字 socket()、bind()、listen()、accept()、connect()、read()、write()、close()

    前面说到的进程间的通信,所通信的进程都是在同一台计算机上的,而使用socket进行通信的进程可以是同一台计算机的进程,也是可以是通过网络连接起来的不同计算机上的进程.通常我们使用socket进行网络编 ...

  5. Go - 字典(map)

    字典是一种内置的数据结构,用来保存 键值对 的 无序集合. (1)字典的创建 1) make(map[KeyType] ValueType, initialCapacity) 2) make(map[ ...

  6. 完整的PHP MYSQL数据库类

    <?php class mysql {     private $db_host; //数据库主机     private $db_user; //数据库用户名     private $db_ ...

  7. .net WebServer例

    新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...

  8. 2.1WebApi的路由

    这篇文章描述 ASP.NET Web API如何将 HTTP 请求通过路由去访问控制器. 如果你熟悉 ASP.NET MVC,Web API 路由是非常类似于 MVC 路由.主要的区别是 Web AP ...

  9. iOS开发——高级篇——iOS中常见的设计模式(MVC/单例/委托/观察者)

    关于设计模式这个问题,在网上也找过一些资料,下面是我自己总结的,分享给大家 如果你刚接触设计模式,我们有好消息告诉你!首先,多亏了Cocoa的构建方式,你已经使用了许多的设计模式以及被鼓励的最佳实践. ...

  10. JavaScript——之对象参数的引用传递

    今天碰到一个问题,怎样把参数变更影响到函数外部,如: <script> var myname = "wood"; A(myname); document.write(m ...