1.首先你得有自己的maven
2.找到自己的maven的setting.xml文件
配置方式如下
<servers>
<server>
<id>maven-releases</id>
<username>kunge</username>
<password>kunge123</password>
</server>
<server>
<id>maven-snapshots</id>
<username>kunge</username>
<password>kunge123</password>
</server>
</servers>
这里配置的用户名和密码根据自己仓库设置的配置
3.这个修改好的之后idea会提示让你导入包,这个地方一定要导入包,否则在发布到maven的时候就会出现401的问题
具体错误展示:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project ons:
Failed to deploy artifacts: Could not transfer artifact com.jiahui:ons:jar:1.0.0-20180613.031401-6 from/to maven-snapshots
(http://10.2.103.10:8081/repository/maven-snapshots/):
Failed to transfer file: http://192.168.52.130:8081/repository/maven-snapshots/com/jiahui/ons/1.0.0-SNAPSHOT/ons-1.0.0-20180613.031401-6.jar.
Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
3.idea使用自己配置的maven的配置文件
eg:
maven的文件目录
D:/apache-maven-3.5.2
maven的setting.xml文件目录
D:\apache-maven-3.5.2\conf\settings.xml
4.在项目的最外层配置打包到maven私服的pom内容
具体配置如下:
<repositories>
<repository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.52.130:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local private nexus</name>
<url>http://192.168.52.130:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
这个id的名称要和server里面配置的id名称保持一致
<id>maven-releases</id>
<name>Releases</name>
指定自己需要发布的maven私服
<url>http://
192.168.52.130
:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
这个id的名称要和server里面配置的id名称保持一致
<id>maven-snapshots</id>
<name>Snapshot</name>
指定自己需要发布的maven私服
<url>http://192.168.52.130:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
5.这些都配置好之后点开idea的maven的命令行,也就是Maven Projects打开自己模块的(我的模块也就是redis)-->Lifecycle-->deploy,点击deploy等待一会
成功的标志:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.827 s
[INFO] Finished at: 2018-06-13T11:02:20+08:00
[INFO] Final Memory: 25M/314M
[INFO] ------------------------------------------------------------------------
6.到自己的maven私服里面看看自己刚刚上传的jar
eg:
打开maven私服仓库
[go](http://192.168.52.130:8081/#browse/browse)
Browse
|
maven-snapshots(或者maven-releases)
|--------com
|--jiahui
|
redis--1.0-2018612.092029-1(jar所在的文件夹)
|
ons --1.0.0-20180613.030218-5(jar所在的文件夹)
|
oss --1.0.0-20180613.014829-5(jar所在的文件夹)