创建仓库
nexus默认存在的仓库类型有以下四种:
- group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;
- hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);
- proxy(代理类型):从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);
- virtual(虚拟类型):虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用);
创建hosted仓库
创建user
发布jar包到仓库
maven的config文件在间需要加入如下代码:
<server>
<id>myLocalRepo</id>
<username>nexususer</username>
<password>nexususer</password>
</server>
maven项目需要加入如下配置
<distributionManagement>
<repository>
<!--此名称要和.m2/settings.xml中设置的ID一致 -->
<id>myLocalRepo</id>
<url>http://192.168.199.202:8081/repository/myLocalRepo/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<!--发布代码Jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<!--发布源码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
在maven项目下执行mvn deploy命令
有可能会遇到下面错误:Maven deploy Return code is: 400, 可参考https://blog.csdn.net/running_snail_/article/details/19821777
由于前面设置仓库是Release版本,所以在打jar包的时候需要把版本号中的-SNAPSHOT去掉,才可以上传jar包到仓库中