---
title: "github maven repository"
author: "polim"
date: "2012-09-27T10:57:44Z"
tags: []
categories: ["互联网"]
slug: "github-maven-repository"
draft: false
lastmod: "2012-09-27T10:57:44Z"
id: 1686564
url: "https://polim.iteye.com/blog/1686564"
---

很多人选择在Github上开源项目，但很多开源项目要依赖一些自己写的jar。如何让用户(使用者)可以通过互联网自动下载所依赖的jar呢？

下面介绍下通过GitHub做maven repository的过程;
1、在GitHub上创建项目(这步操作不细说了，过程很简单，用过GitHub的大家都懂的)
例如：我创建的项目名叫 maven-repository
2、把本地maven项目Build，build生成的maven文件夹上传到Giuhub
3、本地新建maven项目如果需要依赖jar,在pom.xml中增加
<!-- 关联下载地址-->
<repositories>
  <repository>
    <id>maven-repository</id>
    <url>https://raw.github.com/GitHub用户名/项目名/master</url>
  </repository>
</repositories>

<!-- 具体依赖项目-->
<dependency>
  <groupId>具体groupId</groupId>
  <artifactId>具体artifactId</artifactId>
  <version>1.0.0</version>
</dependency>

例如我的GitHub用户是polimo那上面依赖仓库地址就是
https://raw.github.com/polimo/maven-repository/<span style="color:red">master</span>
备注：
1、上面的地址直接输入返回为404，页面是无法看到的
2、master 一定要写上，否则会无法下载
3、如果本地项目依赖的groupId、artifactId跟本地项目中的maven项目groupId、artifactId相对应，则会默认依赖本地项目而不去服务端下载。
4、具体依赖项目 配置中
groupId、artifactId 一定要与依赖项目的groupId、artifactId一致。