Sonatype Nexus Repository Manager 搭建maven 私倉

前言

下載安裝  Nexus Repository Manager      默認賬號/密碼  :   admin/admin123   視版本而定,這裏安裝不做深究,主要對如何配置maven 私倉  和  idea 中 deploy  jar 包 進行記錄。

0.首先創建   四個Repository 對應的各個Repository 的 type  需要注意。

group(倉庫組)、hosted(宿主倉庫)、proxy(代理倉庫)

1.maven-central:         type 爲  proxy   意爲 倉庫中沒有對應的jar 包是需要去遠程   倉庫下載。我這在創建的時候  proxy   填的是阿里的 http://maven.aliyun.com/nexus/content/groups/public/   國內倉庫快些。

2.maven-public:          type  爲  group  其中包含一些其他的倉庫配置時可選    選定想要的倉庫組組成。

 

3.maven-releases   和 maven-snapshots   type   爲  host     他們倆的區別在於   裏邊的權限分別爲

之後就需要配置maven 的settings.xml  

1.配置私倉地址 

 

  <mirror>  
        <id>nexus</id> 
        <mirrorOf>*</mirrorOf>    
        <name>Nexus saic</name>  
        <url>http://localhost:8081/repository/*-public/</url>  
    </mirror>

 

 

2.配置私倉的用戶名密碼 。這裏需要記住這個id   之後的maven  項目中的pom.xml  需要使用

    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

這裏需要記住這個id

3.配置profile

<profile>
      <id>nexus</id>
      <repositories>
           <repository>
              <id>snapshots</id>
              <url>http://localhost:8081/repository/*-snapshots/</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
            <repository>
              <id>releases</id>
              <url>http://localhost:8081/repository/*-releases/</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
      </repositories>
      <pluginRepositories>
            <pluginRepository>
              <id>snapshots</id>
              <url>http://localhost:8081/repository/*-snapshots/</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
            <pluginRepository>
              <id>releases</id>
              <url>http://localhost:8081/repository/*-releases/</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
      </pluginRepositories>
    </profile>

 

 

4.啓用對應id的這個profile

    <activeProfiles>
        <!--make the profile active all the time -->
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

 

配置  maven  項目中的  pom.xml   添加

這其中的id   就需要和上邊的settings.xml  中的server   節點的 id對應上。找到對應的用戶名密碼

<distributionManagement>
  <repository>
    <id>nexus</id>
    <name>releases</name>
    <url>http://localhost:8081/repository/*-releases/</url>
  </repository>
  <snapshotRepository>
    <id>nexus</id>
    <name>snapshots</name>
    <url>http://localhost:8081/repository/*-snapshots/</url>
  </snapshotRepository>
</distributionManagement>

注意:

deploy  snapshots  需要  <version>1.0.1-RELEASE</version>

deploy releases  需要   <version>1.0.1-SNAPSHOT</version>

如有問題請留言。

發佈了21 篇原創文章 · 獲贊 12 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章