Maven私有库搭建

若是构建的 n Maven  项目本地仓库没有对应的依赖包,那么就会去 s Nexus  私服去下载,若是 Nexus 私服也没有此依赖包, 就回去远程中央仓库下载依赖, 这些中央仓库就是 proxy 。 Nexus  私服下载成功后再下载至本地 Maven(可是若是私服没有网络不能正常下载,本地也会跳过私服从新下载) apache

前期准备

 系统须要安装并配置好 JDK,下载好Sonatype Nexus(版本地址:nexus-2.13.0-01-bundle.tar.gz)、maven(版本地址:apache-maven-3.3.9-bin.tar.gz)。提示:nexus3不支持maven不要下错了,下的时候看清楚bash

安装

  1. 解压  
    mkdir nexus
    tar -zxvf nexus-2.13.0-01-bundle.tar.gz -c nexus
  2. 编辑 Nexus 的 conf目录下nexus.properties 文件,配置端口和 work 目录信息(保留默认,能够更具需求调整)
  3. 若是nexus目只有部分用户有读写权限,就须要修改nexus-2.13.0-01/bin下nexus
    cd nexus-2.13.0-01/bin
    vi nexus

    将 RUN_AS_USER 修改成用权限运行的用户网络

    # If specified, the Wrapper will be run as the specified user.
    
    # IMPORTANT - Make sure that the user has the required privileges to write into the Nexus installation directory.
    
    # NOTE - This will set the user which is used to run the Wrapper as well as
    #  the JVM and is not useful in situations where a privileged resource or
    #  port needs to be allocated prior to the user being changed.
    RUN_AS_USER=root
     
  4. 打开8081端口
    • -A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT
  5. 启动服务
    cd nexus-2.13.0-01/bin
    ./nexus start

     

  6. http://192.168.0.112:8081/nexus/ 便可进入页面
  7. 点击右上角的 Log In 进行登陆,默认用户名 admin,默认密码 admin123

Nexus配置

  1. 菜单 Administration/Server 配置邮箱服务地址(若是忘记密码, 能够经过该邮箱找回密码)。舒适提示配置的邮箱须要开通SMTP的服务
    • Hostname 每一个邮箱的smtp有差异,去邮箱网站查找
    • Port 通常默认都是25,若是不是须要修改成该邮箱开通所对应的端口
    • Username 邮箱帐号
    • password 邮箱密码
    • System Email 通常配置和帐号相同
  2. 修改与找回用户密码
    • 点击Security -> User
    • 点击用户 修改其Email
    • 在登陆的时候就能够找回其密码
    • 选中某个用户,右键便可以修改或者重置密码
    • 点击右上角admin 出现的选项中profile,而后就能够修改密码
    • Security 下的用户和角色能够进行权限控制
  3. 建立类库(通常用到的仓库种类是 hosted、proxy)
    • group  仓库组:Nexus 经过仓库组的概念统一管理多个仓库,这样咱们在项目中直接请求仓库组便可请求到仓库组管理的多个仓库
    • hosted 宿主仓库: 主要用于发布内部项目构件或第三方的项目构件 (如购买商业的构件)以及没法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)
      • releases 内部的模块中 release 模块的发布仓库
      • snapshots 发布内部的 SNAPSHOT 模块的仓库
      • 3rd party 第三方依赖的仓库,这个数据一般是由内部人员自行下载以后发布上去
    • proxy  代理仓库:代理公共的远程仓库
    • virtual  虚拟仓库:用于适配 Maven 1;
  4.  设置 全部proxy 代理类型仓库(Apache Snapshots 、Central)准许远程下载。点击config 将Download Remote Indexes 设置为true,而后保存
  5.  本地maven的conf目录下settings.xml 
    • 用户权限设置oracle

      <!--配置权限,使用默认用户-->
      	<servers>
      		<server>
      			<id>nexus-releases</id>
      			<username>deployment</username>
      			<password>deployment123</password>
      		</server>
      		<server> 
      			<id>nexus-snapshots</id>
      			<username>deployment</username>
      			<password>deployment123</password>
      		</server>
      	</servers>
    • 私有库设置在profiles中增长profile,url为仓库组的地址
      <profiles>
      		<profile>
      		<!--id 须要惟一-->
      		   <id>test1</id>
      			    <activation>
                          <activeByDefault>false</activeByDefault>
      					<!-- jdk版本触发激活,配置成本地的jdk版本-->
                          <jdk>1.8</jdk>
                      </activation>
      			    <repositories>
      					<!-- 私有库地址-->
      				    <repository>
      						<id>nexus</id>
      						<url>http://192.168.0.112:8081/nexus/content/groups/public/</url>
      						<releases>
      							<enabled>true</enabled>
      						</releases>
      						<snapshots>
      							<enabled>true</enabled>
      						</snapshots>
      					</repository>
      				</repositories>      
      				<pluginRepositories>
      					<!--插件库地址-->
      					<pluginRepository>
      						<id>nexus</id>
      						<url>http://192.168.0.112:8081/nexus/content/groups/public/</url>
      						<releases>
      							<enabled>true</enabled>
      						</releases>
      						<snapshots>
      							<enabled>true</enabled>
      					   </snapshots>
      					</pluginRepository>
      				</pluginRepositories>
      			</profile>
      	</profiles>

       

    • 激活profile
      <!--激活profile-->
      	<activeProfiles>
      		<activeProfile>test1</activeProfile>
      	</activeProfiles>

       

  6. 更新下Eclipse中的maven下的user settings 而后更新settings的xml文件,而后点击update settings
  7. pom.xml中设置私有库地址
    <distributionManagement>
    		<repository>
    			<id>nexus-releases</id>
    			<name>Nexus Release Repository</name>
    			<url>http://192.168.0.112:8081/nexus/content/repositories/releases/</url>
    		</repository>
    		<snapshotRepository>
    			<id>nexus-snapshots</id>
    			<name>Nexus Snapshot Repository</name>
    			<url>http://192.168.0.112:8081/nexus/content/repositories/snapshots/</url>
    		</snapshotRepository>
    	</distributionManagement>

     

  8. maven在构建(install) 的时候加上 deploy 参数就能够将jar本地jar发布到中央库app

  9. 第三方jar包上传maven

    • 点击3rd 而后选择Artifacts Uploadtcp

    • 选择文件而后设置GAV Definition网站

    • 选择 Select Artifact(s) for Upload 而后选择文件ui

    • 点击add  而后点击uploadurl

相关文章
相关标签/搜索