Make github as your personal maven repository
前言:
开始用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的更多相关文章
- 安装java memcached client到本地maven repository
由于目前java memcached client没有官方的maven repository可供使用,因此使用时需要手动将其安装到本地repository.java memcached client的 ...
- 【Maven】IKAnalyzer 在Maven Repository不存在
1.在mvnrepository里面找IKAnalyzer,这个中文分词包,一直没有找到,找到github,发现是一个国人写的. http://mvnrepository.com/search?q=I ...
- 国内可用maven repository 配置
国内可用maven repository 配置 发表于2016/1/4 23:08:04 10235人阅读 分类: maven 鉴于一些原因,从maven中央仓库download依赖包时,被各种折磨 ...
- 如何利用Maven Repository下载开源软件jar包
1.打开Maven Repository 网站:https://mvnrepository.com/ 2.输入需要寻找的jar包名称,比如mybatis,点击search,一般第一个就是 3.点击选择 ...
- maven repository 配置
eclipse maven 配置修改: maven repository 配置 http://blog.csdn.net/joewolf/article/details/4876604 Maven缺省 ...
- maven安装,使用说明,及maven Repository如何使用.
maven的使用方法总结一下 1.首先去apache官网下载maven, http://maven.apache.org/download.cgi2.如果是windows系统,选择 apache-ma ...
- Maven - Repository(存储库)
版权所有,未经授权,禁止转载 章节 Maven – 简介 Maven – 工作原理 Maven – Repository(存储库) Maven – pom.xml 文件 Maven – 依赖管理 Ma ...
- 将自定义jar包上传github并制作成maven仓库
参照:https://www.jianshu.com/p/98a141701cc7 第一阶段 :配置github 1.创建mvn-repo分支 首先在你的github上创建一个maven-re ...
- Spring Boot从入门到精通(二)配置GitHub并上传Maven项目
简单介绍一下GitHub,它是一个面向开源及私有软件项目的托管平台,因为只支持git作为唯一的版本库格式进行托管,故名GitHub. GitHub于2008年4月10日正式上线,除了Git代码仓库托管 ...
随机推荐
- R语言学习笔记-机器学习1-3章
在折腾完爬虫还有一些感兴趣的内容后,我最近在看用R语言进行简单机器学习的知识,主要参考了<机器学习-实用案例解析>这本书. 这本书是目前市面少有的,纯粹以R语言为基础讲解的机器学习知识,书 ...
- MySQL 5.5开启慢查询功能
vim /etc/my.cnf [mysqld] slow-query-log = on # 开启慢查询功能 slow_query_log_file = /usr/local/mysql/data/s ...
- 自写网站入门阶段之三:兼容大战与jq初探
自上一次作小结至今已整整一个月,在忙乎了半个月的工作之后闲下来的一个下午我终于可以再次作这个阶段的小结了.首先庆幸的是在同学的推荐下我顺利的找到了工作并于月初3号正式上班,这一点非常感谢他,让我免去了 ...
- 01OC概述
目前来说,Objective-C(简称OC)是iOS开发的核心语言,在开发过程中也会配合着使用C语言.C++,OC主要负责UI界面,C语言.C++可用于图形处理.特点如下: 一.OC基于C语言 C语言 ...
- 【转】MVC中处理Json和JS中处理Json对象
事实上,MVC中已经很好的封装了Json,让我们很方便的进行操作,而不像JS中那么复杂了. MVC中: public JsonResult Test() { JsonResult json = new ...
- Qt5.7中使用MySQL Driver
Qt5.7中使用MySQL Driver 1.使用环境 Qt5.7的安装安装就已经带了MySQL Driver,只需要在安装的时候选择一下即可. 如果没有安装,可以采取自己编译的方式. 在Qt的源码包 ...
- 【GWAS文献解读】疟原虫青蒿素抗药性的全基因组关联分析
英文名:Genetic architecture of artemisinin-resistant Plasmodium falciparum 中文名:疟原虫青蒿素抗药性的全基因组关联分析 期刊:Na ...
- Oracel基础知识
1.查看oracle环境变量命令 echo %path% 2.监听程序:Oracle服务器端的一种网络服务.监听程序创建在数据库的服务器端,主要作用监视客户的连接请求.因此在客户端创建监听毫无意义 ...
- Sass安装(windows版)
Sass安装(windows版) 在 Windows 平台下安装 Ruby 需要先有 Ruby 安装包,大家可以到 Ruby 的官网(http://rubyinstaller.org/download ...
- PHP 抽象类 和 interface 接口
静态: 在类里面 定义的变量 在别的地方引用的时候 只要是 静态引用 就一定要加$ 普通成员 : 属于对象的 静态成员: 属于类的 static (通过双冒号调用) 调用静态成员: re ...