使用github作为maven仓库

本文介绍的这种使用 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

时间: 2024-08-30 11:32:56

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

使用GitHub作为Maven仓库并引用

网上太多的博客都是那些傻逼抄袭,然后直接复制粘贴然后就成为自己的博客了,这种人,真的很欠揍,我在网上查了一个下午的资料,终于找到一个写得非常详细的兄弟 链接如下:https://blog.csdn.net/sunxiaoju/article/details/85331265#commentsedit 我就不写了,上面博客的兄弟的方法,我本人亲测有效 原文地址:https://www.cnblogs.com/xjbBill/p/10628056.html

利用github搭建个人maven仓库

缘起 之前看到有开源项目用了github来做maven仓库,寻思自己也做一个.研究了下,记录下. 简单来说,共有三步: deploy到本地目录 把本地目录提交到gtihub上 配置github地址为仓库地址 配置local file maven仓库 deploy到本地 maven可以通过http, ftp, ssh等deploy到远程服务器,也可以deploy到本地文件系统里.例如: <distributionManagement> <repository> <id>h

利用github搭建私人maven仓库

一.背景 最近在做HBase的项目,不免会引用到一些工具类,如StringUtils,NumberUtils,DateUtils这些,公司底层有封装好可以直接使用. 但是项目完成,用maven打包部署的时候,由于公司底层集成了太多jar包,可能会导致冲突,使打完的jar包无法用java -jar 运行,报错是 Error: Invalid or corrupt jarfile realTimeImport-1.0-SNAPSHOT.jar 暂时定位是引用了太多jar包引起的,但其实我可能就只需要

GitHub建立个人Maven仓库

一.配置github 创建mvn-repo仓库 首先在你的github上创建一个maven-repo仓库,这个最后将作为实际上jar包发布的仓库. 设置name 在github的个人设置中,设置好自己的姓名 .这个环节很重要,若不设置姓名,会出现一些一些意想不到的错误. 二.配置部署jar到本地 修改mvn配置文件settings.xml Win+R输入%MAVEN_HOME%打开maven安装目录,修改本地maven的配置文件settings.xml,找到其中的servers 标签,加入如下

创建bitbucket的私有maven仓库,把aar (library)上传到bitbucket的maven仓库(by 星空武哥)

创建bitbucket的私有maven仓库,把aar (library)上传到bitbucket的maven仓库 转载请标注原文地址:http://blog.csdn.net/lsyz0021/article/details/52065404 当我们使用android studio的开发的时候,我们可以很方面的使用compile " "命令很方便的使用别人的第三方aar库 比如我们引用okhttp的时候就可以在gradle中: dependencies { compile 'com.s

[Publish AAR To Maven] 注册 Maven 仓库 sonatype.org 账户

本篇文章隶属于 <使用 Gradle 发布 AAR 到 Maven 仓库> ======================================================== 作者:qiujuer 博客:blog.csdn.net/qiujuer 网站:www.qiujuer.net 开源库:github.com/qiujuer/Genius-Android 转载请注明出处:http://blog.csdn.net/qiujuer/article/details/44195199

[Publish AAR To Maven] 使用 Gradle 发布 AAR 到 Maven 仓库

======================================================== 作者:qiujuer 博客:blog.csdn.net/qiujuer 网站:www.qiujuer.net 开源库:github.com/qiujuer/Genius-Android 转载请注明出处:http://blog.csdn.net/qiujuer/article/details/44195131 --学之开源,用于开源:初学者的心态,与君共勉! =============

将Gradle项目公布到maven仓库

将Gradle项目公布到maven仓库 1 Gradle简单介绍 1.1 Ant.Maven还是Gradle? 1.1.1 Ant和Maven介绍 全称为Apache Maven,是一个软件(特别是Java软件)项目管理及自己主动构建工具,由Apache软件基金会所提供. ?在公布maven之前,android普遍使用ant的方式进行项目的构建和管理.它们均使用XML文件来配置描写叙述项目的,相比較于ant maven提供的功能更加强大. 主要表如今以下几点: - 使用POM的方式来管理和描写叙

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

使用.创造和分享 笔者曾经不思量力的思考过『是什么推动了互联网技术的快速发展?』这种伟大的命题.结论是,除了摩尔定律之外,技术经验的快速积累和广泛分享,也是重要的原因. 有人戏称,『写 Java,首先要学会选包』,在这里不好评论对错.不过这句话里面,至少包含两层意思:首先 Java 有大量的现成的依赖包,不必要自己造轮子:其次,Java 的包存放较为集中,集成方式也方便. 笔者从事 Android 和 Java 开发以来,经历了几个阶段: 闭门造轮子 > 使用别人的轮子 > 开门造轮子 >