如何配置maven項目連接私服(nexus)


maven連接私服的配置分為兩步:

1、配置maven可以連接私服打包上傳項目(maven的deploy指令)
在maven安裝目錄下的配置文件settings.xml中添加:
添加到servers標簽內部

    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server> 

  在項目中的pom.xml文件中添加:

<distributionManagement>
    <repository>
        <id>releases</id>
    <url>http://localhost:8081/nexus/content/repositories/releases/</url>
    </repository> 
    <snapshotRepository>
        <id>snapshots</id>
    <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository> 
  </distributionManagement> 

2、配置maven可以從私服上下載jar包
在maven安裝目錄下的配置文件settings.xml中添加:
添加到profiles標簽內部

<profile>   
    <!--profile的id-->
    <id>dev</id>   
    <repositories>   
      <repository>  
        <!--倉庫id,repositories可以配置多個倉庫,保證id不重復-->
        <id>nexus</id>   
        <!--倉庫地址,即nexus倉庫組的地址-->
        <url>http://localhost:8081/nexus/content/groups/public/</url>   
        <!--是否下載releases構件-->
        <releases>   
          <enabled>true</enabled>   
        </releases>   
        <!--是否下載snapshots構件-->
        <snapshots>   
          <enabled>true</enabled>   
        </snapshots>   
      </repository>   
    </repositories>  
     <pluginRepositories>  
        <!-- 插件倉庫,maven的運行依賴插件,也需要從私服下載插件 -->
        <pluginRepository>  
            <!-- 插件倉庫的id不允許重復,如果重復后邊配置會覆蓋前邊 -->
            <id>public</id>  
            <name>Public Repositories</name>  
            <url>http://localhost:8081/nexus/content/groups/public/</url>  
        </pluginRepository>  
    </pluginRepositories>  
  </profile> 

  在配置文件settings.xml中添加用以激活上面的配置:

<activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>

  


免責聲明!

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



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