Maven相關(guān)知識(shí)點(diǎn)

1、maven setting.xml相關(guān)知道點(diǎn)

<servers>
    <!-- 如果有搭建自己公司的maven私服,公司內(nèi)部會(huì)把自己的公司的公共jar包上傳到maven私服中。
如果私服配置了上傳、或讀取權(quán)限,servers標(biāo)簽需要給出授權(quán)信息。 -->
    <server>
      <id>release-repository</id>
      <username>lengyu</username>
      <password>abcd456rqa</password>
    </server>
  </servers>

2、pom.xml相關(guān)知識(shí)點(diǎn)

<!--定義snapshots庫和releases庫的nexus地址,此節(jié)點(diǎn)放在project根節(jié)點(diǎn)下-->
<!-- 在distributionManagement段中配置的是snapshot快照庫和release發(fā)布庫的地址 -->
<distributionManagement>
  <repository>
    <id>nexus-releases</id>
    <name>Nexus Release Repository</name>
    <url>http://maven.kmengfang.com:4900/nexus/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
     <id>nexus-snapshots</id>
     <name>Nexus Snapshot Repository</name>
     <url>http://maven.kmengfang.com:4900/nexus/content/repositories/snapshots/</url>
   </snapshotRepository>
</distributionManagement>
<!-- 注意這里配置的server的id必須和pom文件中的distributionManagement對(duì)應(yīng)倉庫的id保持一致,maven在處理發(fā)布時(shí)會(huì)根據(jù)id查找用戶名稱和密碼進(jìn)行登錄和文件的上傳發(fā)布。 -->

3、maven常用插件(plugins)

3.1、源碼打包插件:maven-source-plugin

execution下可配置phase屬性, 意思是在什么階段打包源文件。如<phase>package</phase>
執(zhí)行 mvn install,maven會(huì)自動(dòng)將source install到repository 。
執(zhí)行 mvn deploy,maven會(huì)自動(dòng)將source deploy到remote-repository 。
執(zhí)行 mvn source:jar,單獨(dú)打包源碼。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.2.1</version>
  <executions>
     <execution>
       <id>attach-sources</id>
       <phase>package</phase>
       <goals>
          <goal>jar-no-fork</goal>
       </goals>
     </execution>
  </executions>
</plugin>

3.2配置maven依賴構(gòu)件的遠(yuǎn)程倉庫

<!-- 如果此私服需要授權(quán)才能訪問,那么id值kmengfang-nexus則一定要在setting.xml中的servers配置 -->
<repositories>
    <repository>
        <id>kmengfang-nexus</id>
        <name>aliyun nexus</name>
            <url>http://maven.kmengfang.com:4900/nexus/content/groups/public/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

3.3配置maven插件的遠(yuǎn)程倉庫

<!--配置Maven從什么地方下載插件構(gòu)件(如maven-clean-plugin、maven-compiler-plugin等)。
該元素的內(nèi)部配置和<repository>完全一樣-->
<pluginRepositories>  
    <pluginRepository>  
      <id>maven-net-cn</id>  
      <name>Maven China Mirror</name>  
      <url>http://repo1.maven.org/maven2</url>  
      <releases>  
        <!--可以從這個(gè)倉庫下載releases版本的構(gòu)件,配置與repositories一樣-->
        <enabled>true</enabled>  
      </releases> 
     <!--關(guān)閉對(duì)SNAPSHOT的支持,防止不穩(wěn)定的構(gòu)建-->
      <snapshots>  
        <enabled>false</enabled>  
      </snapshots>      
    </pluginRepository>  
  </pluginRepositories>

Maven需要的依賴在本地倉庫中不存在時(shí),Maven會(huì)去配置的遠(yuǎn)程倉庫中查找
Maven需要的插件在本地倉庫中不存在時(shí),Maven不會(huì)去這些遠(yuǎn)程倉庫查找。
所以需要我們配置pluginRepositories倉庫。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評(píng)論 19 139
  • 所有項(xiàng)目的構(gòu)建都是有生命周期的,這個(gè)生命周期包括:項(xiàng)目清理、初始化、編譯、測(cè)試、打包、集成測(cè)試、驗(yàn)證、部署、站點(diǎn)生...
    zlcook閱讀 2,997評(píng)論 0 21
  • Maven編譯代碼的相關(guān)命令 第一、main目錄下的主代碼編寫完畢后,使用Maven進(jìn)行編譯,在項(xiàng)目根目錄下運(yùn)行命...
    加油小杜閱讀 1,436評(píng)論 0 2
  • 當(dāng)前,JVM生態(tài)圈主要的三大構(gòu)建工具: Apache Ant(帶著Ivy) Maven Gradle 對(duì)于剛開始接...
    清楓_小天閱讀 5,978評(píng)論 1 13
  • Spring Boot 參考指南 介紹 轉(zhuǎn)載自:https://www.gitbook.com/book/qbgb...
    毛宇鵬閱讀 47,255評(píng)論 6 342

友情鏈接更多精彩內(nèi)容