Maven倉庫の理解

19986 ワード

前言
mavenを使うのもしばらくの間、repository、mirror、profileを構成するとき、jarが引き出せないことがあります.そこでmavenがjarパケットを取得する際の優先度を真剣に分析した.
Maven倉庫の分類
倉庫分類:ローカル倉庫とリモート倉庫.Mavenは座標に基づいてコンポーネントを探すとき、まずローカルウェアハウスを表示し、ローカルウェアハウスにコンポーネントがある場合は直接使用します.ない場合は、リモート・ウェアハウスから検索し、見つけたらローカルにダウンロードします.
1)ローカルウェアハウスのデフォルトでは、各ユーザは自分のユーザディレクトリにパス名を持つ.m 2/repository/の倉庫ディレクトリ.私たちもsettingsでxmlファイルローカルウェアハウスのアドレスの構成
2)リモートウェアハウスローカルウェアハウスは書斎のようなもので,リモートウェアハウスは書店のようなものである.Mavenの場合、各ユーザーには1つのローカル・ウェアハウスしかありませんが、複数のリモート・ウェアハウスを構成できます.下・
pomファイルに複数のrepositoryを構成できますが、プロジェクトが多くなるにつれてpomファイルで構成するのは面倒になります.settingsファイルでprofile(私服)を構成できます.これにより、新しいプロジェクトを作成するたびにrepositoryを配置する必要がなくなります.
3)中央倉庫Mavenは、少なくとも1つの利用可能なリモート倉庫を知る必要があります.中央倉庫はこのようなデフォルトのリモート倉庫であり、Mavenはsuper pomファイルをデフォルトで持っています.maven super pomファイルの場所D:apache-maven-3.0.4libの下のmaven-model-builder-3.0.4.jarのorg/apache/maven/model/pom-4.0.0.xml
···     
  
    
      central
      Central Repository
      https://repo.maven.apache.org/maven2
      default
      
        false
      
    
  
···

この時、settingsファイルにmirrorのmirrorOfをcentralのミラーが「中央倉庫」に代わる理由が分かった.
Mavenミラー
ミラーリング(Mirroring)は冗長性の一種で、あるディスク上のデータが別のディスク上に完全に同じコピーであるミラーが存在する.なぜミラーを構成するのか.
1.一言で言えば、あなたが持っている私にも、あなたが持っていない私にもあります.(リモートウェアハウスにないjarを含むリモートウェアハウスを所有するすべてのjar)2.やはり一言で言えば、私はあなたより速く走っています.(リモートウェアハウスでjarを取得する速度がミラーより遅い場合があります.これも私たちが一般的に中央ウェアハウスを構成する理由で、外国のmavenウェアハウスでは一般的に取得速度が遅いためです)
mavenミラーを上記の2点のために構成しない場合は、ミラーを構成する必要はありません.注意:リモート・ウェアハウスがミラー・マッチングされると、jarパッケージを取得すると、構成したrepositoryウェアハウスではなくミラー・ウェアハウスから取得され、repositoryは機能しません.
mirrorOfラベル
mirrorOfラベルにはrepository構成のidが配置されています.複雑なニーズを満たすために、Mavenはより高度なミラー構成をサポートしています.
external:* =                 
repo,repo1 =      repo   repo1       
*,!repo1 =               ,  repo1       
* =              

私服
私服は特殊なリモートMaven倉庫であり、ローカルエリアネットワーク内に架設された倉庫サービスであり、私服は一般的にインターネットリモート倉庫のミラーとして構成され、ローカルエリアネットワーク内のMavenユーザーが使用できる.Mavenがコンポーネントをダウンロードする必要がある場合は、まず私服に要求し、私服にコンポーネントが存在しない場合は、外部のリモートウェアハウスからダウンロードし、私服にキャッシュした後、Mavenダウンロード要求にダウンロードサービスを提供します.また、カスタムまたはサードパーティのjarは、ローカルエリアネットワーク内の他のmavenユーザーが使用できるように、ローカルから私服にアップロードすることができます.主なメリットは次のとおりです.
1.       
2.   Maven  
3.        :         jar       ,            
4.      、    :        
5.          :            

Maven倉庫のコンセプトを紹介したので、本題に入ります
Maven倉庫優先度
テストを容易にするために、以下の倉庫を用意しました.
  • 172.16.xxx.xxxリモートウェアハウス(私服)
  • dev.xxx.Wikiリモートウェアハウス(リモート)
  • localhost倉庫は私自身が本機で構築した倉庫(ミラー)
  • です.
  • maven.aliyun.com中央倉庫(中央)
  • ローカルウェアハウスの優先順位
    Mavenローカルウェアハウスはこのパッケージを所有していますが、リモート、ミラー、中央、私服には含まれていません.Mavenがどうやって手に入れたか見てみましょう
    .......
    //       ,   (priority)  10
    [DEBUG] Using local repository at E:\OperSource
    [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for E:\OperSource
    [INFO] Scanning for projects..
    ........
    [INFO] Installing C:\Users\swipal\Desktop\abc\demo\target\demo-1.0-SNAPSHOT.jar to E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\demo-1.0-SNAPSHOT.jar
    [DEBUG] Writing tracking file E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\_remote.repositories
    [INFO] Installing C:\Users\swipal\Desktop\abc\demo\pom.xml to E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\demo-1.0-SNAPSHOT.pom
    [DEBUG] Writing tracking file E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\_remote.repositories
    [DEBUG] Installing com.cjf:demo:1.0-SNAPSHOT/maven-metadata.xml to E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\maven-metadata-local.xml
    [DEBUG] Installing com.cjf:demo/maven-metadata.xml to E:\OperSource\com\cjf\demo\maven-metadata-local.xml
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.874 s
    [INFO] Finished at: 2017-07-07T10:37:32+08:00
    [INFO] Final Memory: 23M/219M
    [INFO] ------------------------------------------------------------------------
    Process finished with exit code 0

    Mavenは最初からローカルウェアハウスを使用し、ローカルウェアハウスの優先度を10にカスタマイズし、jarパッケージもローカルウェアハウスで見つけ、Mavenはパッケージ化に成功したことがわかります.
    リモートウェアハウス優先度
    前述したように、ローカル・ウェアハウスの優先度が最も高いことがわかりました.リモート・ウェアハウスの優先度を検討し続けます(以下のすべての例では、ローカル・ウェアハウスが必要なパッケージを持っていないことがデフォルトです).
    今回はprofile(私服)が172.16.xxx.xxxリモートウェアハウス、repositoryがdev.xxx.wikiリモートウェアハウス、mirrorがローカルlocalhostウェアハウス、mirrorOfがcentralリモートウェアハウスがmaven.aliyun.comの中央ウェアハウス、以下が構成情報settings.xmlファイル
    ······
     
       
        localhost  
        Public Repositories  
        foo   
        http://localhost:8081/repository/maven-public/ 
        
      
       
        localhost2  
        Public Repositories  
        foo2   
        http://localhost:8081/repository/maven-snapshots/ 
        
      
       
        alimaven  
        central  
        aliyun maven  
        http://maven.aliyun.com/nexus/content/groups/public/ 
       
     
    
    
     
       
        nexus  
         
           
            public  
            Public Repositories  
            http://172.16.xxx.xxx:8081/nexus/content/groups/public/ 
           
          
         
           
            public  
            Public Repositories  
            http://172.16.xxx.xxx:8081/nexus/content/groups/public 
           
         
       
    
    
        nexus
    
    ······

    pom.xmlファイル
    
        
        
            com.xxx.cif
            xxx-cif-api
            0.0.1-SNAPSHOT
        
        
        
            com.cjf
            Chapter1
            0.0.1-SNAPSHOT
        
    
    
    
        
            foo
            Public Repositories
            http://dev.xxx.wiki:8081/nexus/content/groups/public/
        
    

    以下はMaven拉取包のログです
    ·······         
    [DEBUG] Using local repository at E:\OperSource
    [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for E:\OperSource
    [INFO] Scanning for projects...
    //                      pom        
    [DEBUG] Using mirror localhost (http://localhost:8081/repository/maven-public/) for foo (http://dev.xxx.wiki:8081/nexus/content/groups/public/).
              
    [DEBUG] Using mirror alimaven (http://maven.aliyun.com/nexus/content/groups/public/) for central (https://repo.maven.apache.org/maven2).
    //         Maven      dependencies   plugins    ,              172.16.xxx.xxx,     localhost      maven.aliyun.com
    //   :alimaven (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)                 releases  ,    snapshots           。(      central      )
    [DEBUG] === PROJECT BUILD PLAN ================================================
    [DEBUG] Project:       com.cjf:demo:1.0-SNAPSHOT
    [DEBUG] Dependencies (collect): []
    [DEBUG] Dependencies (resolve): [compile, runtime, test]
    [DEBUG] Repositories (dependencies): [public (http://172.16.xxx.xxx:8081/nexus/content/groups/public/, default, releases+snapshots), localhost (http://localhost:8081/repository/maven-public/, default, releases+snapshots), alimaven (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)]
    [DEBUG] Repositories (plugins)     : [public (http://172.16.xxx.xxx:8081/nexus/content/groups/public, default, releases+snapshots), alimaven (http://maven.aliyun.com/nexus/content/groups/public/, default, releases)]
    [DEBUG] =======================================================================
    //         maven-metadata.xml      ,           (           )
    [DEBUG] Could not find metadata com.xxx.cif:xxx-cif-api:0.0.1-SNAPSHOT/maven-metadata.xml in local (E:\OperSource)
    //        Maven               ,   Maven           ,          
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://172.16.xxx.xxx:8081/nexus/content/groups/public/
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://localhost:8081/repository/maven-public/
    [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://localhost:8081/repository/maven-public/
    [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://172.16.xxx.xxx:8081/nexus/content/groups/public/
    Downloading: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/maven-metadata.xml
    Downloading: http://localhost:8081/repository/maven-public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/maven-metadata.xml
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\cif\xxx-cif-api\0.0.1-SNAPSHOT\resolver-status.properties
    //          172.16.xxx.xxx     xxx-cif-api   maven-metadata.xml        
    Downloaded: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/maven-metadata.xml (781 B at 7.0 KB/sec)
    //     ,resolver-status.properties     jar         
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\cif\xxx-cif-api\0.0.1-SNAPSHOT\resolver-status.properties
    [DEBUG] Could not find metadata com.xxx.cif:xxx-cif-api:0.0.1-SNAPSHOT/maven-metadata.xml in localhost (http://localhost:8081/repository/maven-public/)
    //   localhost          xxx-cif-api   maven-metadata.xml
    [DEBUG] Could not find metadata com.xxx.cif:xxx-cif-api:0.0.1-SNAPSHOT/maven-metadata.xml in local (E:\OperSource)
    //         
    [DEBUG] Skipped remote request for com.xxx.cif:xxx-cif-api:0.0.1-SNAPSHOT/maven-metadata.xml, already updated during this session.
    [DEBUG] Skipped remote request for com.xxx.cif:xxx-cif-api:0.0.1-SNAPSHOT/maven-metadata.xml, already updated during this session.
    //        xxx-cif-api         localhost    ,            localhost      
    [DEBUG] Failure to find com.xxx.cif:xxx-cif-api:0.0.1-SNAPSHOT/maven-metadata.xml in http://localhost:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of localhost has elapsed or updates are forced
    //   172.16.xxx.xxx       0 ,    xxx-cif-api   pom   
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://172.16.xxx.xxx:8081/nexus/content/groups/public/
    [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://172.16.xxx.xxx:8081/nexus/content/groups/public/
    Downloading: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/xxx-cif-api-0.0.1-20170515.040917-89.pom
    Downloaded: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/xxx-cif-api-0.0.1-20170515.040917-89.pom (930 B at 82.6 KB/sec)
    // _remote.repositories                 (ps:               ,            。)
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\cif\xxx-cif-api\0.0.1-SNAPSHOT\_remote.repositories
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\cif\xxx-cif-api\0.0.1-SNAPSHOT\xxx-cif-api-0.0.1-20170515.040917-89.pom.lastUpdated
    //      Chapter1       com.xxx.cif     ,       localhost      ,            。
    //          ,         
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://172.16.xxx.xxx:8081/nexus/content/groups/public/
    [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://172.16.xxx.xxx:8081/nexus/content/groups/public/
    Downloading: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/xxx-cif-api-0.0.1-20170515.040917-89.jar
    Downloading: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/util/xxx-util/0.0.1-SNAPSHOT/xxx-util-0.0.1-20170514.091041-31.jar
    Downloaded: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/util/xxx-util/0.0.1-SNAPSHOT/xxx-util-0.0.1-20170514.091041-31.jar (26 KB at 324.2 KB/sec)
    Downloaded: http://172.16.xxx.xxx:8081/nexus/content/groups/public/com/xxx/cif/xxx-cif-api/0.0.1-SNAPSHOT/xxx-cif-api-0.0.1-20170515.040917-89.jar (68 KB at 756.6 KB/sec)
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\cif\xxx-cif-api\0.0.1-SNAPSHOT\_remote.repositories
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\cif\xxx-cif-api\0.0.1-SNAPSHOT\xxx-cif-api-0.0.1-20170515.040917-89.jar.lastUpdated
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\util\xxx-util\0.0.1-SNAPSHOT\_remote.repositories
    [DEBUG] Writing tracking file E:\OperSource\com\xxx\util\xxx-util\0.0.1-SNAPSHOT\xxx-util-0.0.1-20170514.091041-31.jar.lastUpdated
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://localhost:8081/repository/maven-public/
    [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://localhost:8081/repository/maven-public/
    Downloading: http://localhost:8081/repository/maven-public/com/cjf/Chapter1/0.0.1-SNAPSHOT/Chapter1-0.0.1-20170708.092339-1.jar
    Downloaded: http://localhost:8081/repository/maven-public/com/cjf/Chapter1/0.0.1-SNAPSHOT/Chapter1-0.0.1-20170708.092339-1.jar (8 KB at 167.0 KB/sec)
    [DEBUG] Writing tracking file E:\OperSource\com\cjf\Chapter1\0.0.1-SNAPSHOT\_remote.repositories
    [DEBUG] Writing tracking file E:\OperSource\com\cjf\Chapter1\0.0.1-SNAPSHOT\Chapter1-0.0.1-20170708.092339-1.jar.lastUpdated
    [INFO] Installing C:\Users\swipal\Desktop\abc\demo\target\demo-1.0-SNAPSHOT.jar to E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\demo-1.0-SNAPSHOT.jar
    [DEBUG] Writing tracking file E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\_remote.repositories
    [INFO] Installing C:\Users\swipal\Desktop\abc\demo\pom.xml to E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\demo-1.0-SNAPSHOT.pom
    [DEBUG] Writing tracking file E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\_remote.repositories
    [DEBUG] Installing com.cjf:demo:1.0-SNAPSHOT/maven-metadata.xml to E:\OperSource\com\cjf\demo\1.0-SNAPSHOT\maven-metadata-local.xml
    [DEBUG] Installing com.cjf:demo/maven-metadata.xml to E:\OperSource\com\cjf\demo\maven-metadata-local.xml
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 10.549 s
    [INFO] Finished at: 2017-07-09T18:13:20+08:00
    [INFO] Final Memory: 26M/219M
    [INFO] ------------------------------------------------------------------------
    ·······

    では、こんなに多くのプロファイル情報とログ情報を見て、Mavenリモートウェアハウスの優先度もまとめました.
    主に以下の点がある:1.ログ情報から、これらのmaven倉庫の優先度は
    ローカルウェアハウス>プライベートウェアハウス>リモートウェアハウス(repository)およびミラー(mirror)>セントラルウェアハウス(central)
    2.ミラーは特殊な構成であり、ミラーはリモートウェアハウスと同等である.リモート・ウェアハウスに一致するミラーがないと機能しません(foo 2のように).3.要約すると、Mavenウェアハウスの優先度は私服とリモートウェアハウスの対比であり、他のウェアハウスタイプはない.なぜなら、ミラーはリモートと同等であり、中央もmaven super xml構成のrepositoryの1つであるからである.したがってmavenウェアハウスの真の優先度は
    ローカルウェアハウス>プライベートウェアハウス>リモートウェアハウス(repository)
    maven-metadata.xmlファイル
    Maven Repository Metadataは、次のように表すことができます.
    1.          :                
    2.     :            
    3.   Maven      :                。
    

    メタデータ・ファイル名は次のとおりです.
            maven-metadata.xml,
    maven-metadata- .xml       ,    repo-id            。
    

    以上はMavenの公式サイトのこのファイルに対する解釈です.
    さぎょう
    質問:最新のパッケージを更新すると、最新のパッケージが引き出されていることがわかりますが、プロジェクトで使用されているパッケージは古いパッケージです.何が原因なのか分析しなければなりません
    まず、maven-metadataについて大まかに理解します.xmlファイル.
    
    
      com.cjf
      Chapter1
      0.0.1-SNAPSHOT
      
                                       
          20170710.071727 
          6           
        
        20170710071727
        
                                
            jar
            0.0.1-20170710.071727-6
            20170710071727     
          
          
            pom
            0.0.1-20170710.071727-6
            20170710071727
          
        
      
    

    ここでlastUpdatedは最も重要な属性であり、Mavenがプロジェクトのjarパッケージを更新すると、lastUpdatedタイムスタンプ値、より大きな値、どのファイルに準拠するかが比較されます.
    次に、Mavenが作成したファイルを見てみましょう.maven-metadataを見ることができます.xmlは全部で3つあります
    1. maven-metadata-local.xml       , Maven install        。
    2. maven-metadata-snapshots.xml Maven deploy     
    3. maven-metadata-localhost.xml             (repository   id = localhost)
    

    以上のファイルはすべてMavenの移行ファイルです
  • 例えばmaven-metadata-snapshotsは、Maven deployが先にリモートウェアハウスから対応するパッケージのmaven-metadataである.xmlをダウンロードし、スナップショット情報を変更してリモートウェアハウスにアップロードします.
  • 例えばmaven-metadata-localhostの役割は、Mavenがパッケージを引き出すときに、lastUpdatedタイムスタンプ値をローカルmaven-metadata-localと比較して、どれを大きく使うかということです.Mavne強制更新の場合(強制更新なしではできない)リモートのmaven-metadataがダウンロードされます.xmlは、リモート、ローカル、および以前にリモートで保存されたmaven-metadataファイルを比較します.

  • したがって、mavenライブラリのjarパッケージが更新されている場合がありますが、mavenのパッケージがなかなか取れないのは、ローカルのmaven-metadata-localのlastUpdatedが大きいためです.
    Maven deployの例を検証します
    [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ Chapter1 ---
    //          maven-metadata.xml
    Downloading: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/maven-metadata.xml
    Downloaded: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/maven-metadata.xml (768 B at 3.3 KB/sec)
    //      jar   pom          
    Uploading: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/Chapter1-0.0.1-20170710.121310-15.jar
    Uploaded: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/Chapter1-0.0.1-20170710.121310-15.jar (8 KB at 14.1 KB/sec)
    Uploading: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/Chapter1-0.0.1-20170710.121310-15.pom
    Uploaded: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/Chapter1-0.0.1-20170710.121310-15.pom (2 KB at 2.0 KB/sec)
    Downloading: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/maven-metadata.xml
    Downloaded: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/maven-metadata.xml (275 B at 1.6 KB/sec)
    //     maven-metadata.xml      
    Uploading: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/maven-metadata.xml
    Uploaded: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/0.0.1-SNAPSHOT/maven-metadata.xml (768 B at 1.0 KB/sec)
    Uploading: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/maven-metadata.xml
    Uploaded: http://localhost:8081/repository/maven-snapshots/com/cjf/Chapter1/maven-metadata.xml (275 B at 0.4 KB/sec)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 5.231 s
    [INFO] Finished at: 2017-07-10T20:13:13+08:00
    [INFO] Final Memory: 19M/226M
    [INFO] ------------------------------------------------------------------------

     
    まとめ
    2日でこの文章を書くと思っていたが、自分で考えを整理している間にいつも自分に気を取られてしまった.例えばNexusのCentral構成の中央倉庫で取得し、maven-metadata.xmlはどのように比較されますか.
    もし以上の文章が間違っていたら、ブログのコメントシステムが構築されたら、皆さんのご指摘を歓迎します.