用GitHub构建个人Maven仓库

来源:互联网 发布:淘宝考试答题器 编辑:程序博客网 时间:2024/04/30 23:17

用GitHub构建个人Maven仓库

Maven是一个出色的项目管理工具,它的依赖管理功能极其方便。但是对于个人开发者而言,发布jar包到中央仓库略显麻烦,有时候一些jar包也不适合发布到中央仓库,这时便可以利用GitHub来发布jar包,并利用它的raw服务提供对外下载功能。

准备工作

你需要:

  • 一个配置好ssh-key的GitHub账户 https://github.com
  • git运行环境 http://git-scm.com
  • maven运行环境 http://maven.apache.org

开始搭建

创建一个新的GitHub仓库,记下地址:git@github.com:liuhuanting/maven.git
进入你主机的maven本地仓库.m2/repository,初始化git本地仓库,添加远程地址:

123
cd ~/.m2/repositorygit initgit remote add origin git@github.com:liuhuanting/maven.git

创建.gitignore文件并提交:

123
echo *>>.gitignoregit add .gitignoregit commit -m 'add .gitignore'

创建分支并提交:

123
git branch snapshotgit push origin snapshotgit checkout snapshot

找到你要发布的.jar文件,将它部署到本地Maven仓库:

1
mvn install:install-file -Dfile=timo-parser-1.0.0.jar -DgroupId=com.github.liuhuanting -DartifactId=timo-parser -Dversion=1.0.0 -Dpackaging=jar

将本地Maven仓库对应的文件提交到GitHub:

1234
cd ~/.m2/repositorygit add -f com/github/liuhuanting/timo-parser/1.0.0git commit -m 'snapshot of timo-parser-1.0.0'git push origin snapshot

好了,仓库的搭建和jar包的发布都已经完成了。

开始使用

你可以在项目的pom.xml文件中使用该依赖了:

12345678910111213141516171819
<project>  <repositories>    <repository>      <id>liuhuanting-maven-snapshot-repository</id>      <name>liuhuanting-maven-snapshot-repository</name>      <url>https://raw.github.com/liuhuanting/maven/snapshot/</url>    </repository>  </repositories>    <dependencies>    <dependency>      <artifactId>timo-parser</artifactId>      <groupId>com.github.liuhuanting</groupId>      <version>1.0.0</version>    </dependency>  </dependencies>  </project>
1 0
原创粉丝点击