nexus私服搭建及maven生命週期

1、maven找庫流程java

  

  從流程上看建立nexus私服,可以優化流程,並且更加快速apache

2、nexus下載、安裝vim

  一、nexus下載地址   緩存

https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.5-02-bundle.tar.gz

   二、nexus解壓並安裝環境 安全

#解壓
tar -zxif nexus-2.14.5-02-bundle.tar.gz
#在環境變量中設置啓動用戶
vim /etc/profile
#安全起見不建議使用root用戶,若是使用其它用戶須要加相應權限
RUN_AS_USER=root

   三、配置啓動參數服務器

#${nexusBase}爲nexus的安裝路徑
vim ${nexusBase}/conf/nexus.properties
#端口號
applicatiom-port=8081
#倉庫地址
nexus-work=${bundleBasedir}/../sonatype-work/nexus
#啓動nexus
${nexusBase}/bin/nexus start
#中止nexus
${nexusBase}/bin/nexus stop

   四、登陸nexus界面app

地址:http://{ip}:8081/nexus/
默認用戶名:admin
默認密碼:admin123

   五、手動更新索引框架

    前往maven中央倉庫下載indexer-cli-5.1.1.jar maven

http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.apache.maven.indexer%22%20AND%20a%3A%22indexer-cli%22

   六、下載索引文件ide

http://repo.maven.apache.org/maven2/.index/
nexus-maven-repository-index.gz
nexus-maven-repository-index.properties

   七、解壓索引文件

java -jar indexer-cli-5.1.1.jar -u nexus-maven-repository-index.gz -d indexer

        八、拷貝索引文件至目錄

{nexus-home}/sonatype-work/nexus/indexer/central-ctx

   九、重啓nexus

  注意:以爲麻煩能夠直接下載:https://pan.baidu.com/s/1qzllVcr5nqiX2EKVlof5Wg,裏面包含全部須要的文件

3、maven配置優化及設置

  一、優化maven裏的setting配置

#設置maven本地倉庫地址
<localRepository>F:\maven</localRepository>
#設置快照版本服務
<servers>
      #對應exclipe/idea項目中parent,pom.xml裏的distributionManagement
      <id>nexusSnapshot</id>
      <username>deployment</username>
      <password>deployment123</password>
    </server>
</servers>
#設置鏡像
<mirrors>
	<mirror>
		<id>nexusSnapshot</id>
                #所有走nexus私服
		<mirrorOf>*</mirrorOf>
		<name>nexus</name>
		<url>http://192.168.1.32:8082/nexus/content/groups/public/</url>
     </mirror>
 </mirrors>
#配置倉庫地址
<profiles>
	<profile>
	  <id>common</id>
      <repositories>
        <repository>
          <id>nexusSnapshot</id>
          <name>snapshots</name>
          <url>http://*</url>
        </repository>
		<repository>
          <id>nexusCentral</id>
          <name>nexusCentral</name>
          <url>http://*</url>
        </repository>
		<repository>
          <id>nexusReleases</id>
          <name>nexusReleases</name>
          <url>http://*</url>
        </repository>
      </repositories>
        #配置編譯的jdk
	  <properties> 
		  <maven.compiler.source>1.8</maven.compiler.source> 
		  <maven.compiler.target>1.8</maven.compiler.target> 
		      <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> 
	  </properties> 
	</profile>
  </profiles>

<activeProfiles>
    <activeProfile>common</activeProfile>
  </activeProfiles>

   二、修改pom.xml

<distributionManagement>
		<repository>
			<id>nexusSnapshot</id>
			<name>nexusSnapshot</name>
			<url>http://192.168.1.32:8082/nexus/content/repositories/snapshots/</url>
		</repository>
	</distributionManagement>

 4、nexus倉庫與倉庫組

  一、nexus內置倉庫

  登錄用戶,單擊Nexus界面左邊導航欄中的Repositories連接,就能夠看到內置的倉庫

 

  二、從中能夠看到倉庫有四種類型:

- group(倉庫組)
- hosted(宿主)
- proxy(代理)
- virtual(虛擬)

   三、每一個倉庫的格式爲maven2或者maven1。此外,倉庫還有一個屬性爲Policy(策略),表示該倉庫爲發佈(Release)版本倉庫仍是快照(Snapshot)版本倉庫。最後兩列的值爲倉庫的狀態和路徑。

    Maven Central:該倉庫代理Maven中央倉庫,其策略爲Release,所以只會下載和緩存中央倉庫中的發佈版本構件。
    Releases:這是一個策略爲Release的宿主類型倉庫,用來部署組織內部的發佈版本構件。
    Snapshots:這是一個策略爲Snapshot的宿主類型倉庫,用來部署組織內部的快照版本構件。
    3rd party:這是一個策略爲Release的宿主類型倉庫,用來部署沒法從公共倉庫得到的第三方發佈版本構件。
    Apache Snapshots:這是一個策略爲Snapshot的代理倉庫,用來代理Apache Maven倉庫的快照版本構件。
    Codehaus Snapshots:這是一個策略爲Snapshot的代理倉庫,用來代理Codehaus Maven倉庫的快照版本構件。
    Google Code:這是一個策略爲Release的代理倉庫,用來代理Google Code Maven倉庫的發佈版本構件。
    java.net-Maven 2:這是一個策略爲Release的代理倉庫,用來代理java.net Maven倉庫的發佈版本構件。
    Public Repositories:該倉庫組將上述全部策略爲Release的倉庫聚合並經過一致的地址提供服務。
    Public Snapshot Repositories:該倉庫組將上述全部策略爲Snapshot的倉庫聚合並經過一致的地址提供服務。

   四、Nexus倉庫分類的概念

5、maven生命週期

  

clean lifecycle : 構建前的清理工做
•	pre-clean 執行一些須要在clean以前完成的工做
•	clean 移除全部上一次構建生成的文件
•	post-clean 執行一些須要在clean以後馬上完成的工做
Default lifecycle: 構建的核心部分,編譯、打包、部署、上傳
•	validate 項目及所必須的環境驗證
•	initialize 初始化構建狀態,例如設置屬性或建立目錄。
•	generate-sources 生成次源包
•	process-sources
•	generate-resources
•	process-resources 複製並處理資源文件,至目標目錄,準備打包。
•	compile 編譯項目的源代碼。
•	process-classes
•	generate-test-sources 
•	process-test-sources 
•	generate-test-resources
•	process-test-resources 複製並處理資源文件,至目標測試目錄。
•	test-compile 編譯測試源代碼。
•	process-test-classes
•	test 使用合適的單元測試框架運行測試。這些測試代碼不會被打包或部署。
•	prepare-package
•	package 接受編譯好的代碼,打包成可發佈的格式,如 JAR 。
•	pre-integration-test
•	integration-test
•	post-integration-test
•	verify
•	install 將包安裝至本地倉庫,以讓其它項目依賴。
•	deploy 將最終的包複製到遠程的倉庫,以讓其它開發人員與項目共享。
site lifecycle:項目報告生成,站點文檔生成
•	pre-site 執行一些須要在生成站點文檔以前完成的工做
•	site 生成項目的站點文檔
•	post-site 執行一些須要在生成站點文檔以後完成的工做,而且爲部署作準備
•	site-deploy 將生成的站點文檔部署到特定的服務器上

 個人博客即將搬運同步至騰訊雲+社區,邀請你們一同入駐:https://cloud.tencent.com/developer/support-plan?invite_code=ej6dteqjfixd

相關文章
相關標籤/搜索