本地环境:
OS X 10.10.2
nexus2.11.1
服务器环境:
Centos 6.5
JDK7
1.下载启动
axel http://download.sonatype.com/nexus/oss/nexus-2.11.1-01-bundle.zip
unzip nexus-2.11.1-01-bundle.zip
cd nexus-2.11.1-01/bin/
#使用 root 用户启动
export RUN_AS_USER=root
#启动服务
./nexus start
2.设置
启动之后浏览器打开
http://192.168.100.100:8081/nexus/#welcome
默认用户名admin
,密码admin123
;
2.1.下载maven2官方仓库索引
1.如图
2.在Central右键,Update Index
2.2.用户设置
- 关闭匿名用户
- 修改管理员账户密码
- 设置有部署权限和开发权限的用户,部署权限用户可以发布到 maven 仓库
3.项目中使用
3.1.设置仓库验证信息
修改本地配置~/.m2/settings.xml
其中添加 maven server的验证信息
<servers>
<server>
<id>novacloud</id>
<username>xxx</username>
<password>xxx</password>
</server>
</servers>
这样所有id 为 novacloud 的仓库都会走这个验证信息
3.2.普通maven项目中使用
在 pom 中添加 repo 即可,指定 id 为设置中的
<repositories>
<repository>
<id>novacloud</id>
<url>http://192.168.100.100:8081/nexus/content/groups/public/</url>
</repository>
</repositories>
3.3.play 项目中使用
- play 是使用的 ivy 获取的 maven 仓库数据,所以验证信息要在 ivy 中设定.
打开 ~/.ivy2/ivysettings.xml
<credentials host="192.168.100.100" realm="Sonatype Nexus Repository Manager"
username="xxx" passwd="xxx"/>
2.依赖文件配置
dependencies.yml
require:
- com.google.code.maven-play-plugin.org.playframework -> play 1.2.7
- com.google.code.maven-play-plugin.org.playframework.modules.morphia -> play-morphia 1.2.12
- com.novacloud.data -> novadata-model 1.3.4
- com.novacloud.data -> roadrunner 1.0
repositories:
- novacloud:
type: iBiblio
root: "http://192.168.100.100:8081/nexus/content/repositories/public/"
contains:
- com.novacloud.data -> *
````
-----------
###4.发布文件到maven 私有仓库
设置要发布项目的 pom
<distributionManagement>
<repository>
<id>novacloud-releases</id>
<name>NovaCloud Release Repository</name>
<url>http://192.168.100.100:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>novacloud-snapshots</id>
<name>NovaCloud Snapshot Repository</name>
<url>http://192.168.100.100:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
然后使用``mvn deploy ``命令即可发布到对应的仓库.
添加插件即可同时发布源码
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
注意:版本号不包括 SNAPSHOT 的时候,maven 仓库中只能存在一个相同的版本。第二次再发布会报错。
当版本是x.x.x-SNAPSHOT的时候,每次deploy 都会发布到 maven 仓库。
参考:
```
http://blog.csdn.net/zzq900503/article/details/41699273
http://my.oschina.net/aiguozhe/blog/101537
http://maven.oschina.net/help.html
https://www.playframework.com/documentation/1.2.x/dependency
http://sgq0085.iteye.com/blog/1861173
http://blog.csdn.net/songdeitao/article/details/20658443
http://www.qiyadeng.com/?p=435
```
Comments