使用nexus构建maven私服
2016-01-20 10:55
435 查看
现在用maven构建的项目越来越多,部署一个私有的仓库拥有较大的价值:
1、方便项目组的人员之间共享类库
2、maven的jar包版本管理能更好地管理jar包
3、减少对中央仓库的依赖。
当下载一个snapshot或release时,maven查找的顺序为 本地仓库-->私服仓库-->中央仓库。部署私有仓库后,每当访问私有仓库查找时,若不存在,私有仓库即会从中央仓库下载,以后其他开发人员再次下载时因为私有仓库已有该artifact所以都会从私有仓库下载。由于私服多数部署在内网,所以网络之间的传输由外网变成内网。
=============================================================
vi /etc/init.d/nexus
设置以下内容
使用chkconfig命令增加开机自动启动
启动nexus: service nexus start
默认的访问地址是 http://{ip}:8081/nexus
nexus默认的三个账户
有两种修改密码的方式
(1)、在用户界面登陆后修改
(2)、直接修改security.xml配置文,修改后重启nexus后生效
nexus使用SHA1的加密码方式,把加密后的密码替换<password>标签的内容即可
由于匿名用户也拥有读权限,在安全性要求高的代码仓库可以删除匿名用户的读权限。
若想使用mvn:deploy命令直接部署至nexus则需在pom.xml增加部署插件、打包源码插件(推荐)
编辑$MAVEN_HOME/conf/settings.xml文件增加部署的帐户
配置完毕后就可以愉快的使用mvn:deploy命令把jar和源码一起发布至nexus私服了
1、方便项目组的人员之间共享类库
2、maven的jar包版本管理能更好地管理jar包
3、减少对中央仓库的依赖。
当下载一个snapshot或release时,maven查找的顺序为 本地仓库-->私服仓库-->中央仓库。部署私有仓库后,每当访问私有仓库查找时,若不存在,私有仓库即会从中央仓库下载,以后其他开发人员再次下载时因为私有仓库已有该artifact所以都会从私有仓库下载。由于私服多数部署在内网,所以网络之间的传输由外网变成内网。
=============================================================
1、下载并解压
cd /usr/local/src wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.12.0-01-bundle.tar.gz
tar -zxvf nexus-2.12.0-01-bundle.tar.gz -directory=/usr/local cd /usr/local ln -s nexus-2.12.0-01 nexus
2、把nexus设成系统服务
cp /usr/local/nexus/bin/nexus /etc/init.d/ chown +x /etc/init.d/nexus chmod 755 /etc/init.d/nexus
vi /etc/init.d/nexus
设置以下内容
RUN_AS_USER=root NEXUS_HOME="/usr/local/nexus" PIDDIR="${NEXUS_HOME}/bin/jsw/linux-x86-64"
使用chkconfig命令增加开机自动启动
chkconfig --add nexus chkconfig nexus on
启动nexus: service nexus start
默认的访问地址是 http://{ip}:8081/nexus
3、修改默认密码
nexus默认的三个账户帐号 | 默认密码 | 权限 |
---|---|---|
admin | admin123 | 管理员 |
deployment | deployment123 | 读、发布 |
anomynous | 无 | 读 |
(1)、在用户界面登陆后修改
(2)、直接修改security.xml配置文,修改后重启nexus后生效
vi /usr/local/sonatype-work/nexus/conf/security.xml
<user> <id>deployment</id> <firstName>Deployment</firstName> <lastName>User</lastName> <password>b2a0e378437817cebdf753d7dff3dd75483af9e0</password> <status>active</status> <email>changeme1@yourcompany.com</email> </user>
nexus使用SHA1的加密码方式,把加密后的密码替换<password>标签的内容即可
4、去除anonymous用户的浏览respository的权限(可选)
由于匿名用户也拥有读权限,在安全性要求高的代码仓库可以删除匿名用户的读权限。vi /usr/local/sonatype-work/nexus/conf/security.xml
<userRoleMapping> <userId>anonymous</userId> <source>default</source> <roles> <role>anonymous</role> <!-- <role>repository-any-read</role> --> <!-- 删除读权限 --> </roles> </userRoleMapping>
5、在maven项目的pom.xml文件加入
<!-- 仓库地址 --> <repositories> <repository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://192.168.30.61:8081/nexus/content/groups/public</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Team Nexus Repository</name> <url>http://192.168.30.61:8081/nexus/content/groups/public</url> </pluginRepository> </pluginRepositories>
<!-- 发布地址 --> <distributionManagement> <repository> <id>releases</id> <!-- 若要使用mvn:deploy命令须与settings.xml文件的server标签的id对应 --> <name>Nexus Release Repository</name> <url>http://192.168.30.61:8081/nexus/content/repositories/releases/</url> </repository> <snapshotRepository> <id>snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://192.168.30.61:8081/nexus/content/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
若想使用mvn:deploy命令直接部署至nexus则需在pom.xml增加部署插件、打包源码插件(推荐)
<!-- 部署插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.4</version> </plugin>
<!-- 打包源码插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>attach-sources</id> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin>
编辑$MAVEN_HOME/conf/settings.xml文件增加部署的帐户
<server> <server> <id>releases</id> <!-- 要与pom.xml的发布仓库中的id对应 --> <username>admin</username> <password>123456</password> </server> </servers>
配置完毕后就可以愉快的使用mvn:deploy命令把jar和源码一起发布至nexus私服了
相关文章推荐
- QMouseEvent 的坐标__Win
- Scala - error: not found: value SortedMap
- 动态选择商品
- Cloudera 之旅 ☞ 【一】环境熟悉
- Memcache存储大数据的问题
- PHP微信开发新浪sea服务器提示token验证失败
- ant编译代码时报错error: unmappable character for encoding ASCII
- 翻转View
- MarkdownPad2.5 注册码
- React-Native获取文本框的值
- uva12096
- opencv从入门到精通(1)-创建自己的视频播放器
- php CLI的使用与扩展安装
- 内存管理
- Specification_&_Datasheet_&_Books
- ko的 dependentObservable 引用自身声明方式
- MapReduce算法设计-Second Sorting
- C++中内存分配详解
- Android 首次创建数据库或者更新时,SQLiteOpenHelper的使用与解析
- AndroidStudio操作笔记--简单介绍1