本文介绍的这种使用 github 作为 maven 仓库的思路主要为:

  1. github的项目上创建mvn-repo分支,使用mvn-repo分支作为maven仓库
  2. 配 置 pom.xml 使用 target/mvn-repo 作为本地部署的临时maven仓库
  3. 部署时使用 github site-maven-plugin 将本地的maven仓库 push 到 github 的项目的分支 mvn-repo 上去

以我的项目为例:https://github.com/buzheng/mybatis-pageable

首先通过配置pom.xml告诉maven将artifacts部署到一个target下的一个临时目录中,具体配置如下:

<plugin>
true<artifactId>maven-deploy-plugin</artifactId>
true<version>2.8.1</version>
true<configuration>
truetrue<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
true</configuration>
</plugin>

配置完成后,运行命令 mvn clean deploy 后发现已经部署maven仓库到 target/mvn-repo 目录下。然后我们要做的就是将该目录上传到github中。

在 ~/.m2/settings.xml 中添加github的授权信息,以便 github 的 site-maven-plugin 能够push文件到github,配置信息如下:

<server>
<id>github</id>
<username>你在github的帐号</username>
<password>你在github的用户名</password>
</server>

添加如下配置到 pom.xml 以告诉 github site-maven-plugin 服务器信息

<properties>
true<!-- github server corresponds to entry in ~/.m2/settings.xml -->
true<github.global.server>github</github.global.server>
</properties>

最后配置 github site-maven-plugin 插件

<plugin>
true<groupId>com.github.github</groupId>
true<artifactId>site-maven-plugin</artifactId>
true<version>0.9</version>
true<configuration>
truetrue<message>Maven artifacts for ${project.version}</message> <!-- git commit message -->
truetrue<noJekyll>true</noJekyll> <!-- disable webpage processing -->
truetrue<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory> <!-- matches distribution management repository url above -->
truetrue<branch>refs/heads/mvn-repo</branch> <!-- remote branch name -->
truetrue<includes>
truetruetrue<include>**/*</include>
truetrue</includes>
truetrue<repositoryName>mybatis-pageable</repositoryName> <!-- github repo name -->
truetrue<repositoryOwner>buzheng</repositoryOwner> <!-- github username -->
true</configuration>
true<executions>
truetrue<!-- run site-maven-plugin's 'site' target as part of the build's normal
truetruetrue'deploy' phase -->
truetrue<execution>
truetruetrue<goals>
truetruetruetrue<goal>site</goal>
truetruetrue</goals>
truetruetrue<phase>deploy</phase>
truetrue</execution>
true</executions>
</plugin>

配置完成,运行命令 mvn clean deploy后,登录github,发现已经创建 mvn-repo 分支,并上传了 本地的 target/mvn-repo 目录。

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mybatis-pageable 0.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mybatis-pageable ---
[INFO] Deleting E:\workspace\mybatis-pageable\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mybatis-pageable ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mybatis-pageable ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to E:/workspace/mybatis-pageable/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mybatis-pageable ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mybatis-pageable ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mybatis-pageable ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mybatis-pageable ---
[INFO] Building jar: E:/workspace/mybatis-pageable/target/mybatis-pageable-0.1.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mybatis-pageable ---
[INFO] Installing E:/workspace/mybatis-pageable/target/mybatis-pageable-0.1.jar to C:/Users/Adam.my-pc/.m2/repository/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.jar
[INFO] Installing E:/workspace/mybatis-pageable/pom.xml to C:/Users/Adam.my-pc/.m2/repository/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.8.1:deploy (default-deploy) @ mybatis-pageable ---
[INFO] Using alternate deployment repository internal.repo::default::file://E:/workspace/mybatis-pageable/target/mvn-repo
Uploading: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.jar
Uploaded: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.jar (15 KB at 1020.2 KB/sec)
Uploading: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.pom
Uploaded: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/0.1/mybatis-pageable-0.1.pom (4 KB at 907.5 KB/sec)
Downloading: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/maven-metadata.xml
Uploading: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/maven-metadata.xml
Uploaded: file://E:/workspace/mybatis-pageable/target/mvn-repo/org/buzheng/mybatis-pageable/maven-metadata.xml (303 B at 147.9 KB/sec)
[INFO]
[INFO] --- site-maven-plugin:0.9:site (default) @ mybatis-pageable ---
[INFO] Creating 9 blobs
[INFO] Creating tree with 10 blob entries
[INFO] Creating commit with SHA-1: ac8a117fa05c3a24f057a684519d5edade5d4e64
[INFO] Updating reference refs/heads/mvn-repo from cf1389181d9559b6926a26e852aa2b605b46da1e to ac8a117fa05c3a24f057a684519d5edade5d4e64
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.124s
[INFO] Finished at: Mon Jun 16 15:47:54 CST 2014
[INFO] Final Memory: 24M/178M
[INFO] ------------------------------------------------------------------------

到此为止,项目的已经部署到github上。如果其他项目依赖此项目,需要在pom.xml中添加如下配置后,再添加相应的依赖关系即可。

<repositories>
true<repository>
truetrue<id>mybatis-pageable-mvn-repo</id>
truetrue<url>https://raw.github.com/buzheng/mybatis-pageable/mvn-repo/</url>
true</repository>
</repositories>

完成!

这种方法相当方便,只需要几个简单的配置,便能自动将jar包发布到github上。

参考:http://stackoverflow.com/questions/14013644/hosting-a-maven-repository-on-github

使用github作为maven仓库的更多相关文章

  1. 使用github作为maven仓库存放发布自己的jar包依赖 实现多个项目公共部分代码的集中,避免团队中多个项目之间代码的复制粘贴

    使用github作为maven仓库存放发布自己的jar包依赖 实现多个项目公共部分代码的集中,避免团队中多个项目之间代码的复制粘贴. 1.首先在本地maven位置的配置文件setting.xml(没有 ...

  2. Github作为Maven仓库

    新建发布构件项目 新建一个普通的maven项目,坐标为 创建一个类: 接着在pom文件中添加: <distributionManagement> <repository> &l ...

  3. 使用GitHub作为Maven仓库并引用

    网上太多的博客都是那些傻逼抄袭,然后直接复制粘贴然后就成为自己的博客了,这种人,真的很欠揍,我在网上查了一个下午的资料,终于找到一个写得非常详细的兄弟 链接如下:https://blog.csdn.n ...

  4. 如何使用GitHub创建Maven私有仓库

    [Github上创建仓库] 首先,在GitHub上创建自己的仓库(mvn-repo): [配置本地setting文件] 找到本地的maven settings文件,配置server: 有两种选择,可以 ...

  5. 利用github搭建个人maven仓库

    之前看到有开源项目用了github来做maven仓库,寻思自己也做一个.研究了下,记录下. 简单来说,共有三步: deploy到本地目录 把本地目录提交到gtihub上 配置github地址为仓库地址 ...

  6. 利用github搭建私人maven仓库

    一.背景 最近在做HBase的项目,不免会引用到一些工具类,如StringUtils,NumberUtils,DateUtils这些,公司底层有封装好可以直接使用. 但是项目完成,用maven打包部署 ...

  7. 发布jar包到远端github仓库使用(将github仓库当作maven仓库)

    今天把单点登陆的core模块搬到了github仓库 并且利用github仓库作为maven仓库 在项目中进行了引用 1. 起初看技术博客没有完全引入进来,调整了一下OK了 2. 还可以将其他模块或者工 ...

  8. 拥抱 Android Studio 之四:Maven 仓库使用与私有仓库搭建

    使用.创造和分享 笔者曾经不思量力的思考过『是什么推动了互联网技术的快速发展?』这种伟大的命题.结论是,除了摩尔定律之外,技术经验的快速积累和广泛分享,也是重要的原因. 有人戏称,『写 Java,首先 ...

  9. 国内下载比较快的Maven仓库镜像

    #收集的比较快的maven仓库 http://maven.wso2.org/nexus/content/groups/public/ http://jcenter.bintray.com/http:/ ...

随机推荐

  1. codeforces 689E E. Mike and Geometry Problem(组合数学)

    题目链接: E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes ...

  2. Java-Runoob-高级教程-实例-字符串:10. Java 实例 - 测试两个字符串区域是否相等-uncheck

    ylbtech-Java-Runoob-高级教程-实例-字符串:10. Java 实例 - 测试两个字符串区域是否相等 1.返回顶部 1. Java 实例 - 测试两个字符串区域是否相等  Java ...

  3. 【411】COMP9024 Assignment1 问题汇总

    1. 构建 Makefile 文件后运行错误,undefined reference to 'sqrt' 实际上是没有链接math数学库,所以要 $gcc test.c –lm //-lm就是链接到m ...

  4. bootstrap table 分页后,重新搜索的问题

    前提: 自定义搜索且有分页功能,比如搜索产品名的功能. 现象:当搜索充气娃娃的时候返回100条记录,翻到第五页.  这时候搜索按摩棒,数据有200条,结果应该是第一页的记录,但是实际显示的还是第五页的 ...

  5. bzoj 4521: [Cqoi2016]手机号码【数位dp】

    比较基础的数位dp,dfs的时候带上上一位,上上位,是否已经有连续3个相同位,是否有4,是否有8即可 但是要注意两点(在洛谷上一直70) 当l=1e10的时候,直接输出clc(r)即可,因为如果再减去 ...

  6. bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】

    贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...

  7. 再谈spark部署搭建和企业级项目接轨的入门经验(博主推荐)

    进入我这篇博客的博友们,相信你们具备有一定的spark学习基础和实践了. 先给大家来梳理下.spark的运行模式和常用的standalone.yarn部署.这里不多赘述,自行点击去扩展. 1.Spar ...

  8. python爬虫爬取汽车页面信息,并附带分析(静态爬虫)

    环境: windows,python3.4 参考链接: https://blog.csdn.net/weixin_36604953/article/details/78156605 代码:(亲测可以运 ...

  9. linux自动连接校园网设置

    不知道有没有人用linux的时候碰到过校园网连接后,跳不出登录界面,即使手动输入也没有作用.写一个可能可行的方法: - 首先打开控制面板 选择网络代理 将代理中的选项设置为 估计现在就能自动弹出登录页 ...

  10. Windows 下 IIS与Apache 共存

    在Windows服务器下, 安装了IIS以及Apache服务器, 如何使他们一起工作. 目前我面对的问题是, 只有一个IP地址,要通过不同的端口来访问不同的程序. 解决方案如下: 1.找到 Apach ...