码迷,mamicode.com
首页 > 其他好文 > 详细

使用Nexus搭建maven私服

时间:2016-07-15 09:36:09      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

环境

  • Ubuntu14.04 64位
  • Jdk 1.8.0_60
  • nexus-2.13.0-01-bundle
  • maven 3.3.3

Nexus安装

下载

从Nexus官网下载开源版本Nexus OSS,选择自带jetty容器的bundle版本nexus-2.13.0-01-bundle.tar.gz:
http://www.sonatype.com/download-oss-sonatype
上述文件放在/opt目录下,并解压(tar -zxvf nexus-2.13.0-01-bundle.tar.gz),得到目录/opt/nexus-2.13.0-01。(以下操作的默认目录)

配置

  • conf/nexus.properties文件
    配置运行端口以及工作目录,以下配置是的Nexus运行在8081端口,工作目录为/opt/sonatype-work。
  1. application-port=8081
  2. application-host=0.0.0.0
  3. nexus-webapp=${bundleBasedir}/nexus
  4. nexus-webapp-context-path=/nexus
  5. nexus-work=${bundleBasedir}/../sonatype-work/nexus
  6. runtime=${bundleBasedir}/nexus/WEB-INF
  • bin/nexus文件
    简便起见,只配置一条信息,即使用root用户运行。
  1. RUN_AS_USER=root

运行

使用以下命令运行:

  1. bin/nexus start

可在浏览器查看是否运行成功,若出现后面的界面则说明运行成功。
点击右上角的登录,使用默认的admin/admin123登录。
http://10.110.13.141:8081/nexus/#welcome
技术分享

技术分享

配置文件

  • 设置索引
    点击左侧的Repositories,在Repositories列出的多个库的Configuration的Deployment Policy选择Allow Redeploy。

技术分享
下载远程索引(Download Remote Indexes),选择True:

技术分享

  • maven的settings.xml
    配置了搭建的Nexus maven库的镜像地址,以及用户名和密码等。
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  5. <servers>
  6. <server>
  7. <id>releases</id>
  8. <username>admin</username>
  9. <password>admin123</password>
  10. </server>
  11. <server>
  12. <id>snapshots</id>
  13. <username>admin</username>
  14. <password>admin123</password>
  15. </server>
  16. </servers>
  17. <mirrors>
  18. <mirror>
  19. <id>central</id>
  20. <mirrorOf>*</mirrorOf>
  21. <url>http://10.110.13.141:8081/nexus/content/groups/public/</url>
  22. </mirror>
  23. </mirrors>
  24. <profiles>
  25. <profile>
  26. <id>nexusProfile</id>
  27. <!--all requests to nexus via the mirror -->
  28. <repositories>
  29. <repository>
  30. <id>central</id>
  31. <url>http://central</url>
  32. <releases><enabled>true</enabled></releases>
  33. <snapshots><enabled>true</enabled></snapshots>
  34. </repository>
  35. </repositories>
  36. <pluginRepositories>
  37. <pluginRepository>
  38. <id>central</id>
  39. <url>http://central</url>
  40. <releases><enabled>true</enabled></releases>
  41. <snapshots><enabled>true</enabled></snapshots>
  42. </pluginRepository>
  43. </pluginRepositories>
  44. </profile>
  45. </profiles>
  46. <activeProfiles>
  47. <activeProfile>nexusProfile</activeProfile>
  48. </activeProfiles>
  49. </settings>

项目通过Maven部署到Nexus

这里指本地开发的项目发布到Nexus的maven仓库中,以便小组其他成员依赖发布的jar包。
本地项目使用IntelliJ IDEA开发,需要在pom.xml文件中加入以下配置:

  • 在project根目录下添加库信息
  1. <groupId>com.inspur.sdk</groupId>
  2. <artifactId>qiandu</artifactId>
  3. <version>1.0-SNAPSHOT</version>
  4. <repositories>
  5. <repository>
  6. <id>central</id>
  7. <name>Central</name>
  8. <url>http://10.110.13.141:8081/nexus/content/groups/public/</url>
  9. <releases>
  10. <enabled>true</enabled>
  11. </releases>
  12. <snapshots>
  13. <enabled>true</enabled>
  14. </snapshots>
  15. </repository>
  16. </repositories>
  17. <pluginRepositories>
  18. <pluginRepository>
  19. <id>central</id>
  20. <name>Central</name>
  21. <url>http://10.110.13.141:8081/nexus/content/groups/public/</url>
  22. <releases>
  23. <enabled>true</enabled>
  24. </releases>
  25. </pluginRepository>
  26. </pluginRepositories>
  27. <distributionManagement>
  28. <repository>
  29. <id>releases</id>
  30. <name>Nexus Release Repository</name>
  31. <url>http://10.110.13.141:8081/nexus/content/repositories/releases/</url>
  32. </repository>
  33. <snapshotRepository>
  34. <id>snapshots</id>
  35. <name>Nexus Snapshots Repository</name>
  36. <url>http://10.110.13.141:8081/nexus/content/repositories/snapshots/</url>
  37. </snapshotRepository>
  38. </distributionManagement>
  • 在project/build/plugins下添加部署的plugin节点
  1. <plugin>
  2. <artifactId>maven-deploy-plugin</artifactId>
  3. <version>2.8.1</version>
  4. <executions>
  5. <execution>
  6. <id>default-deploy</id>
  7. <phase>deploy</phase>
  8. <goals>
  9. <goal>deploy</goal>
  10. </goals>
  11. </execution>
  12. </executions>
  13. </plugin>

完整的settings.xml和pom.xml文件见附件

  • 部署到Nexus
    在terminal中运行以下命令:
  1. mvn clean deploy

若显示以下信息则提示部署成功:

  1. [INFO] ------------------------------------------------------------------------
  2. [INFO] BUILD SUCCESS
  3. [INFO] ------------------------------------------------------------------------
  4. [INFO] Total time: 15.934 s
  5. [INFO] Finished at: 2016-07-14T20:22:41+08:00
  6. [INFO] Final Memory: 29M/179M
  7. [INFO] ------------------------------------------------------------------------
  • 搜索依赖
    搜索qiandu,可以在Nexus 库中找到部署的依赖:

技术分享

本地普通jar包部署到Nexus

  • 选择3rd party或者Releases等库下的Artifact Upload
  • 填写GAV 参数信息
  • 选择上传的jar包
  • Add Artifact
  • Upload Artifact(s)

技术分享

技术分享

测试本地Nexus私服

新建maven项目,编写以下依赖,进行Maven测试:

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>com.inspur.test</groupId>
  5. <artifactId>nexus</artifactId>
  6. <packaging>war</packaging>
  7. <version>1.0-SNAPSHOT</version>
  8. <name>nexus Maven Webapp</name>
  9. <url>http://maven.apache.org</url>
  10. <repositories>
  11. <repository>
  12. <id>central</id>
  13. <name>Central</name>
  14. <url>http://10.110.13.141:8081/nexus/content/groups/public/</url>
  15. <releases>
  16. <enabled>true</enabled>
  17. </releases>
  18. <snapshots>
  19. <enabled>true</enabled>
  20. </snapshots>
  21. </repository>
  22. </repositories>
  23. <pluginRepositories>
  24. <pluginRepository>
  25. <id>central</id>
  26. <name>Central</name>
  27. <url>http://10.110.13.141:8081/nexus/content/groups/public/</url>
  28. <releases>
  29. <enabled>true</enabled>
  30. </releases>
  31. </pluginRepository>
  32. </pluginRepositories>
  33. <distributionManagement>
  34. <repository>
  35. <id>releases</id>
  36. <name>Nexus Release Repository</name>
  37. <url>http://10.110.13.141:8081/nexus/content/repositories/releases/</url>
  38. </repository>
  39. <snapshotRepository>
  40. <id>snapshots</id>
  41. <name>Nexus Snapshots Repository</name>
  42. <url>http://10.110.13.141:8081/nexus/content/repositories/snapshots/</url>
  43. </snapshotRepository>
  44. </distributionManagement>
  45. <dependencies>
  46. <dependency>
  47. <groupId>junit</groupId>
  48. <artifactId>junit</artifactId>
  49. <version>3.8.1</version>
  50. <scope>test</scope>
  51. </dependency>
  52. <dependency>
  53. <groupId>com.inspur.loushang</groupId>
  54. <artifactId>loushang-framework</artifactId>
  55. <version>2016</version>
  56. </dependency>
  57. <dependency>
  58. <groupId>com.inspur.qiandu</groupId>
  59. <artifactId>qiandu-utils</artifactId>
  60. <version>1.0-SNAPSHOT</version>
  61. </dependency>
  62. <dependency>
  63. <groupId>com.inspur.sdk</groupId>
  64. <artifactId>qiandu</artifactId>
  65. <version>1.0-SNAPSHOT</version>
  66. </dependency>
  67. </dependencies>
  68. <build>
  69. <finalName>nexus</finalName>
  70. </build>
  71. </project>

参考资料

【1】SonaType Nexus OSS installation on Ubuntu 14.04 LTS
https://asadbukhariblog.wordpress.com/2015/08/31/sonatype-nexus-oss-installation-on-ubuntu-14-04-lts/

【2】Maven入门指南⑤:使用Nexus搭建Maven私服
http://www.cnblogs.com/luotaoyeah/p/3791966.html

【3】Maven Deploy to Nexus
http://www.baeldung.com/maven-deploy-nexus

【4】Maven及Nexus私服搭建
http://www.blogjava.net/ldwblog/archive/2013/11/19/406529.html





附件列表

     

    使用Nexus搭建maven私服

    标签:

    原文地址:http://www.cnblogs.com/myitroad/p/5672369.html

    (0)
    (0)
       
    举报
    评论 一句话评论(0
    登录后才能评论!
    © 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
    迷上了代码!