nexus 的使用及maven的配置


一、nexus的安裝

1.下載nexus(點解這里)

2.下載后解壓文件,將解壓后的nexus文件放在你自己想要的地方

3.配置環境變量(和配置java的環境變量一樣)

4.安裝和啟動nexus

由於我已經安裝和啟動過nexus,所以有錯誤信息提示

5.啟動成功后,在瀏覽器輸入http://localhost:8081/nexus/就會進入nexus的操作界面

我們也可以在conf/nexus.properties修改端口

6.用admin登錄成功后,可以看到如下界面

我們可以看見type有多重類型,這里我們介紹三種:

  • hosted,本地倉庫(也叫宿主倉庫),通常我們會部署自己的構件到這一類型的倉庫或則是第三方的包(如:oracel的)。
  • proxy,代理倉庫,它們被用來代理遠程的公共倉庫,如maven中央倉庫。
  • group,倉庫組,用來合並多個hosted/proxy倉庫,通常我們配置maven依賴倉庫組。

二、使用nexus的管理界面上傳jar包

 

三、創建自己的私有倉庫

 

四、創建權限

 

五、創建角色

五、創建用戶

六、關聯自己的私有倉庫

1.在settings.xml文件中添加鏡像文件關聯

  <mirrors>
    <mirror>     
      <id>nexus-releases</id>     
      <mirrorOf>*</mirrorOf>     
      <url>http://localhost:8081/nexus/content/groups/public</url>     
    </mirror> 
     <mirror>     
       <id>nexus-snapshots</id>     
      <mirrorOf>*</mirrorOf>     
       <url>http://localhost:8081/nexus/content/repositories/apache-snapshots/</url>     
     </mirror> 
  </mirrors>

2.在settings.xml文件中設置profile

  </profiles>    
    <profile>  
        <id>nexusTest</id>  
        <repositories>  
          <repository>  
            <id>local-nexus</id>  
            <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
            <releases>  
              <enabled>true</enabled>  
            </releases>  
            <snapshots>  
              <enabled>true</enabled>  
            </snapshots>  
          </repository>  
        </repositories>  
      </profile>  
  </profiles>


  <activeProfiles> <!--激活id為nexusTest的profile-->
    <activeProfile>nexusTest</activeProfile>
  </activeProfiles>

 

七、發布自己的快照版本到私有倉庫

這里我們測試將的nexusTest.jar發布到myRepository倉庫中

1.在pom.xml中添加

<distributionManagement>
        <!--自己創建的庫-->
       <repository>
            <id>myReposioryT</id><!--這里的id與角色中配置的id要一致-->
            <name>my test reposiory</name>
            <url> http://localhost:8081/nexus/content/repositories/myRepository</url>
        </repository>
        <!--snapshots庫-->
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
      <!--<repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
        </repository>
       -->
    </distributionManagement>

1.在settings.xml文件中添加

    <servers>  
         <server>  
            <id>myReposioryT</id> <!-- 這里的id要與pom.xml中的一致  表示使用該賬號上傳jar到自己建立的my test reposiory倉庫中-->
            <username>testAdmin</username>  
            <password>123456</password>  
          </server>  
      <server>  
        <id>nexus-releases</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server>  
      <server>  
        <id>nexus-snapshots</id>  
        <username>admin</username>  
        <password>admin123</password>  
      </server>     
    </servers>  

使用maven的package deploy 命令就可以將自己的項目打成jar包發布到自己的私有倉庫。

注意,要發布jar包,需要將修改 <packaging>war</packaging>為 <packaging>jar</packaging>

附錄:

1.如果使用idea,則有很好的工具幫我們操作

 2.如果我們版本號后面有后最SNAPSHOT,如<version>1.1-SNAPSHOT</version>

    我們即使是發布到release版本,nexus還是會自動認為是snapshot版本。處理的方式有兩種。

  2.1直接去掉版本號后面的SNAPSHOT后綴,如:<version>1.1</version>

  2.2使用如下配置

//頭部版本號的配置 
<version>${project.release.version}</version>

//添加properties
  <properties>
        <project.release.version>1.1-SNAPSHOT</project.release.version>
    </properties>

 <profiles>
        <profile>
            <id>myRelease</id>  <!--id自己隨便取 使用mvn命令發布的時候要使用到這個id-->
            <properties>
                <project.release.version>1.1</project.release.version>
            </properties>
        </profile>
    </profiles>

 發布的時候使用命令 mvn deploy -P myRelease  (myRelease是profile取得id值)

 這樣發布的時候會使用我們在profile中定義的properties中的變量值去替換<version></version>中的值

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM