介绍
setting.xml主要用于配置maven的运行环境等一系列通用的属性,是全局级别的配置文件;
而pom.xml主要描述了项目的maven坐标,依赖关系,开发者需要遵循的规则,缺陷管理系统,组织和licenses,以及其他所有的项目相关因素,是项目级别的配置文件。
# maven jar包是否存在查看地址
# maven 配置github私有仓库
特此鸣谢外链
github 新建一个仓储
- 新建仓库必须要创建readme.md文件,否则会报409 错误
maven settings.xml 中增加如下内容
- 登录名是github account中配置的名称(就是每个仓储前的节点)
<server>
<id>github</id>
<username>github登陆名</username>
<password>github登陆密码</password>
</server>
1
2
3
4
5
2
3
4
5
- 在需要上传到github仓储的maven项目pop.xml文件中配置如下内容
- 注意有的pop.xml中已有properties节点
<properties>
<github.global.server>github</github.global.server>
</properties>
1
2
3
2
3
<plugin>
<artifactId> maven-deploy-plugin </artifactId>
<version>2.8.2</version>
<configuration>
<altDeploymentRepository> internal.repo::default::file://${project.build.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.version}</message>
<noJekyll>true</noJekyll>
<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory><!--本地jar地址-->
<branch>refs/heads/master</branch><!--分支的名称-->
<merge>true</merge>
<includes>
<include>**/*</include>
</includes>
<repositoryName>mvn-repo</repositoryName><!--对应github上创建的仓库名称 name-->
<repositoryOwner>91xqk</repositoryOwner><!--github 仓库所有者即登录用户名-->
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
- 执行部署命令
mvn clean deploy
1
执行可能遇到的问题
- 解决方法:在github上创建的仓库里创建README.md文件。
[ERROR] Failed to execute goal com.github.github:site-maven-plugin:0.12:site (de fault) on project maven-sampler: Error creating blob: Git Repository is empty. ( 409) -> [Help 1]1- 解决的方法:在github的个人设置中,设置好自己的姓名 。这个环节很重要,若不设置姓名,会出现一些一些意想不到的错误
[ERROR] Failed to execute goal com.github.github:site-maven-plugin:0.11:site (default) on project alta-maven-plugin: Error creating commit: Invalid request. [ERROR] [ERROR] nil is not a string. [ERROR] nil is not a string. (422) [ERROR] -> [Help 1]1
2
3
4
5- 解决的方法:使用jdk1.8 或修改jdk1.7的协议版本为高版本(这个问题我实现时没有遇到,不过看原文提到,所以摘过来给大家参考)
[ERROR] Failed to execute goal com.github.github:site-maven-plugin:0.12:site (default) on project parent: Error retrieving user info: Not Found (404) -> [Help 1]1
# 使用github maven 仓库
- pop.xml 配置内容
- 可能会出现raw.github.com 不能访问,需要配置一下host
添加以下内容保存即可 (IP地址查询后相应修改,可以ping不同IP的延时 选择最佳IP地址) # GitHub Start 52.74.223.119 github.com 192.30.253.119 gist.github.com 54.169.195.247 api.github.com 185.199.111.153 assets-cdn.github.com 151.101.76.133 raw.githubusercontent.com 151.101.108.133 user-images.githubusercontent.com 151.101.76.133 gist.githubusercontent.com 151.101.76.133 cloud.githubusercontent.com 151.101.76.133 camo.githubusercontent.com 151.101.76.133 avatars0.githubusercontent.com 151.101.76.133 avatars1.githubusercontent.com 151.101.76.133 avatars2.githubusercontent.com 151.101.76.133 avatars3.githubusercontent.com 151.101.76.133 avatars4.githubusercontent.com 151.101.76.133 avatars5.githubusercontent.com 151.101.76.133 avatars6.githubusercontent.com 151.101.76.133 avatars7.githubusercontent.com 151.101.76.133 avatars8.githubusercontent.com1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# GitHub End
```
<repositories>
<repository>
<id>mvn-repo</id>
<!-- /用户名/仓库名/分支名/-->
<url>https://raw.github.com/91xqk/mvn-repo/master/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 添加依赖
<dependency>
<groupId>com.xxx</groupId>
<artifactId>包名</artifactId>
<version>版本号</version>
</dependency>
1
2
3
4
5
6
7
2
3
4
5
6
7