创建一个github的repository目录来当作私人maven仓库
目的:
因为想给自己经常会用到的jar依赖包找一个地方来存放,当然需要能通过maven来管理,自己搭私有仓库费钱费力气,按以往经验看都比较短命。上网查询了一番,得知可以拿gibhub来当maven仓库,就也想尝试下!
倒腾了大半天,总算明白了大概!
基本思路:
1 本地指定一个目录专门用来存放本地打包构建的jar包
2 在github上也要创建一个对应的目录
3 然后每次deploy的时候把jar包拷贝到这个本地目录中,然后调用git命令同步到github远程仓库的目录
4 其它项目或者别人就可以用这个远程github的目录来引用下载jar了
具体步骤:
1 注册一个独立的github帐号,新创建一个repository ,名字随意。就只为了放打包编译的class,source等jar
先按提示初始化这个repository,不然后面找不到这个工程
2 要做jar包构建deploy发布的项目pom.xml配置如下
<?xml version="1.0" encoding="UTF-8"?>
<project 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/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.xxxxxx</groupId>
<artifactId>spring-web-xxxx</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<properties>
<github.global.server>github-maven</github.global.server>
<repository.directory>C:\Users\bluces\github\repository</repository.directory>
</properties>
<distributionManagement>
<repository>
<id>github-maven</id>
<url>https://raw.githubusercontent.com/myloginname/mvn-repo/master</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository>internal.repo::default::file://${repository.directory}/mvn-repo</altDeploymentRepository>
</configuration>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.12</version>
<configuration>
<message>Maven artifacts for ${project.artifactId}-${project.version}</message>
<noJekyll>true</noJekyll>
<outputDirectory>${repository.directory}/mvn-repo</outputDirectory>
<branch>refs/heads/master</branch>
<includes>
<include>**/*</include>
</includes>
<repositoryName>mvn-repo</repositoryName>
<repositoryOwner>myloginname</repositoryOwner>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
说明1 :
<github.global.server>github-maven</github.global.server> <repository.directory>C:\Users\bluces\github\repository</repository.directory>
这2个值和下面的配置要一致
说明2:
<distributionManagement><repository><url>https://raw.githubusercontent.com/myloginname/mvn-repo/master
这个地址上的raw.githubusercontent.com可以替换成对应的github.com,是同一份内容,为什么用这个我也没搞清楚,网上拷贝的。
说明3:
<plugin><configuration>
<altDeploymentRepository>internal.repo::default::file://${repository.directory}/mvn-repo</altDeploymentRepository>
本地maven仓库目录地址
说明4 :
git上传的核心插件com.github.github
<plugin><configuration><outputDirectory> 配置的是本地maven仓库目录地址
<plugin><configuration><repositoryName> github上创建的仓库名称
<plugin><configuration><repositoryOwner>github登录账号 对应的密码存在maven的setting.xml文件中
<server>
<id>github-maven</id>
<username>github登录账号</username>
<password>密码</password>
</server>
私有仓库开始使用:
<repository>
<id>maven-github</id>
<url>https://raw.github.com/xxxxx/maven-repo/master</url>
</repository>