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

相關文章
相關標籤/搜索