前言
这篇文章记录下我在Linux14下,使用nexus搭建私人maven仓库的过程。
安装
下载
https://www.sonatype.com/download-oss-sonatype网页上显示的3.x不支持maven,所以下载了2.x。
解压
tar -zxvf nexus-2.14.1-01-bundle.tar.gz 解压,把bin目录添加到PATH
环境变量
运行
nexus start(/restart/stop) 运行nexus
在网页里输入网址 http://mabinbin.com:8081/nexus/ 登录,点击右上角log in登录,默认账号为admin,默认密码为admin123
配置
登录后网页是这个样子的
右上角的列表就是nexus已经添加的仓库,我就使用3rd party。
注意:看到图片里注解3处Repository Policy选择Release,这个仓库只能管理release的组件,不能管理snapshot的组件,如果你要上传项目,pom.xml里面version节点里包含SNAPSHOT则会失败。
部署项目到仓库,通过网页
点击图片里注解4处的Artifacr Upload上传
部署项目到仓库,通过mvn命令
- 1 在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>net.qingtian.maven</groupId>
<artifactId>upload2</artifactId>
<version>0.5</version>
<packaging>jar</packaging>
<distributionManagement>
<repository>
<id>thirdparty</id>
<name>name_thirdparty</name>
<url>http://mabinbin.com:8081/nexus/content/repositories/thirdparty</url>
</repository>
</distributionManagement>
</project>
- 2 在~/.m2/setting.xml 添加server节点,添加账号密码,注意server里的id和上面distributionManagement里仓库的id对应
<settings>
<servers>
<server>
<id>thirdparty</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>
- 3 在项目根目录下执行 mvn deploy 部署到仓库
使用刚才添加的jar包
- 1 在~/.m2/setting.xml 添加repository节点
<settings>
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://mabinbin.com:8081/nexus/content/repositories/thirdparty/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>thirdparty</id>
<username>admin</username>
<password>wodemima</password>
</server>
</servers>
</settings>
- 2 在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>net.qingtian.maven</groupId>
<artifactId>download</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>net.qingtian.maven</groupId>
<artifactId>upload2</artifactId>
<version>0.5</version>
</dependency>
</dependencies>
</project>
参考
http://maven.apache.org/plugins/maven-deploy-plugin/usage.html