Nexus下載構件失敗

問題:我在使用org.apache.httpcomponents:httpclient:4.5:jar時,maven總是從我的私服下載失敗。
我的本地倉庫路徑配置在這裏:
本地倉庫路徑配置
操作1:解決這個問題僅僅在eclipse裏工程右鍵Maven -> Update Project是不夠的,最好在Run -> Maven build裏配置Goals爲clean compile -X或者勾選Debug Output,這樣在更新依賴時就會顯示更詳細的解析下載依賴過程。
這裏寫圖片描述

思考1:但是下載構件並不總是成功。我下載org.apache.httpcomponents:httpclient:4.5:jar失敗,其實並不僅僅於此。該構件會依賴commons-logging-1.2.jar和commons-codec-1.9.jar。這兩個構件同樣下載失敗。所以要解決httpclient-4.5.jar的問題,要先下載commons-logging-1.2.jar和commons-codec-1.9.jar構件。

操作2:以commons-logging-1.2.jar爲例,首先查看Nexus私服本地是否已下載構件:Repositories -> Central -> Browse Storage,commons-logging:commons-logging:1.2下面只有commons-logging.pom文件。這時在commons-logging上右鍵 > Expire Cache,然後Delete,然後Update Index(這三個操作我在很多博客上看到的,並不十分確定有效,但確實成功過)。接着刪除Maven的本地倉庫(不是私服的倉庫)下commons-logging:commons-logging:1.2的所有文件。重新Maven build。最後查看本地倉庫是否下載成功commons-logging-1.2.jar構件。

思考2:按照上步的操作,結果並不總是成功。某種情況下(甚至是多種情況下),仍會多次重現問題。不過要確認一個事情,對於代理倉庫,Update Index任務要下載遠程倉庫的索引,而網絡不好時(通常遠程倉庫在國外,網絡不好是常有的),任務會執行失敗。如下:

jvm 2    | 2015-08-12 10:22:07 INFO  [pool-1-thread-1] - org.sonatype.nexus.tasks.ExpireCacheTask - Scheduled task (ExpireCacheTask) started :: Expiring caches for repository Central from path /commons-logging/commons-logging/1.2/ and below.
jvm 2    | 2015-08-12 10:22:08 INFO  [pool-1-thread-1] - org.sonatype.nexus.tasks.ExpireCacheTask - Scheduled task (ExpireCacheTask) finished :: Expiring caches for repository Central from path /commons-logging/commons-logging/1.2/ and below. (started 2015-08-12T10:22:07+08:00, runtime 0:00:00.625)
jvm 2    | 2015-08-12 10:22:10 INFO  [pool-1-thread-1] - org.sonatype.nexus.tasks.UpdateIndexTask - Scheduled task (UpdateIndexTask) started :: Updating repository index "Central" from path /commons-logging/commons-logging/1.2/ and below.
jvm 2    | 2015-08-12 10:22:10 INFO  [pool-1-thread-1] - org.sonatype.nexus.index.DefaultIndexerManager - Trying to get remote index for repository "Central" [id=central]
jvm 2    | 2015-08-12 10:23:13 WARN  [pool-1-thread-1] - org.sonatype.nexus.index.DefaultIndexerManager - Cannot fetch remote index for repository "Central" [id=central]
jvm 2    | java.net.SocketTimeoutException: Read timed out
jvm 2    |  at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.6.0_05]
jvm 2    |  at java.net.SocketInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.BufferedInputStream.read1(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.BufferedInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at org.apache.commons.httpclient.ContentLengthInputStream.read(Unknown Source) ~[commons-httpclient-3.1.SONATYPE.jar:3.1]
jvm 2    |  at java.io.FilterInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at org.apache.commons.httpclient.AutoCloseInputStream.read(Unknown Source) ~[commons-httpclient-3.1.SONATYPE.jar:3.1]
jvm 2    |  at org.sonatype.nexus.util.WrappingInputStream.read(WrappingInputStream.java:59) ~[nexus-utils-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.proxy.storage.remote.commonshttpclient.HttpClientInputStream.read(HttpClientInputStream.java:95) ~[nexus-proxy-2.0.4-1.jar:na]
jvm 2    |  at java.io.BufferedInputStream.read1(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.BufferedInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.BufferedInputStream.fill(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.BufferedInputStream.read1(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.BufferedInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.util.zip.InflaterInputStream.fill(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.util.zip.InflaterInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.util.zip.GZIPInputStream.read(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at java.io.DataInputStream.readFully(Unknown Source) ~[na:1.6.0_05]
jvm 2    |  at org.apache.maven.index.updater.IndexDataReader.readUTF(IndexDataReader.java:193) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.IndexDataReader.readField(IndexDataReader.java:162) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.IndexDataReader.readDocument(IndexDataReader.java:137) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.IndexDataReader.readIndex(IndexDataReader.java:90) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.DefaultIndexUpdater.unpackIndexData(DefaultIndexUpdater.java:509) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.DefaultIndexUpdater.loadIndexDirectory(DefaultIndexUpdater.java:197) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.DefaultIndexUpdater.access$300(DefaultIndexUpdater.java:76) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.DefaultIndexUpdater$LuceneIndexAdaptor.addIndexChunk(DefaultIndexUpdater.java:636) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.DefaultIndexUpdater.fetchAndUpdateIndex(DefaultIndexUpdater.java:829) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.apache.maven.index.updater.DefaultIndexUpdater.fetchAndUpdateIndex(DefaultIndexUpdater.java:157) ~[indexer-core-4.1.3-SONATYPE.jar:4.1.3-SONATYPE]
jvm 2    |  at org.sonatype.nexus.index.DefaultIndexerManager.updateRemoteIndex(DefaultIndexerManager.java:1131) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.index.DefaultIndexerManager.downloadRepositoryIndex(DefaultIndexerManager.java:1016) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.index.DefaultIndexerManager.reindexRepository(DefaultIndexerManager.java:890) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.index.DefaultIndexerManager.reindexRepository(DefaultIndexerManager.java:838) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.index.DefaultIndexerManager.reindexRepository(DefaultIndexerManager.java:812) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.tasks.ReindexTaskHandlerLegacy.reindexRepository(ReindexTaskHandlerLegacy.java:54) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.tasks.AbstractIndexerTask.doRun(AbstractIndexerTask.java:69) [nexus-indexer-lucene-plugin-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.nexus.scheduling.AbstractNexusTask.call(AbstractNexusTask.java:152) [nexus-app-2.0.4-1.jar:na]
jvm 2    |  at org.sonatype.scheduling.DefaultScheduledTask.call(DefaultScheduledTask.java:459) [plexus-task-scheduler-1.6.0.jar:na]
jvm 2    |  at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) [na:1.6.0_05]
jvm 2    |  at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.6.0_05]
jvm 2    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [na:1.6.0_05]
jvm 2    |  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [na:1.6.0_05]
jvm 2    |  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [na:1.6.0_05]
jvm 2    |  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.6.0_05]
jvm 2    |  at java.lang.Thread.run(Unknown Source) [na:1.6.0_05]

操作3:如果上步不能解決你的問題,只能用笨法了。在私服上,Repositories -> Central -> Browse Storage,commons-logging:commons-logging:1.2右鍵View Remote,直接下載jar和pom文件,然後拷貝到私服倉庫的路徑裏。我的路徑如下:
這裏寫圖片描述
然後Update Index。接着刪除本地倉庫commons-logging:commons-logging:1.2下的所有文件,重新執行Maven build。


  • 名詞解釋

Expire Repository Caches

Repositories have several caches to improve performance. 
This task expires the caches causing Nexus to recheck the remote repository for a proxy repository or the file system for a hosted repository. 
You can configure the repository or group to be affected with the task setting Repository/-Group. 
Alternatively you can provide a Repository Path to configure the content that should be expired.
倉庫的緩存是爲了提升性能。
使緩存失效的任務會引發Nexus重新檢查代理倉庫的遠程倉庫或者宿主倉庫的本地文件系統。
你可以通過配置使任務作用於倉庫或倉庫組,甚至於一個倉庫的路徑。

Repair Repositories Index

In certain cases it might be required to remove the internal index as well as the published ones of a repository. 
This task does that and then rebuilds the internal index by first trying to download remote indexes (if a proxy repository), 
then scanning the local storage and updating the internal index accordingly. 
Lastly, the index is published for the repository as well. 
There should be no need to schedule this task. 
But when upgrading Nexus, the upgrade instructions may sometimes include a manual step of executing this task.
有些情況下,我們需要移除內部索引,還有某個倉庫裏已經發布的索引。
該任務做以上事情,接着會先嚐試下載遠程索引(對於代理倉庫而言)進而重建內部索引,然後掃描本地倉庫同時相應地更新內部索引。
最後,索引就隨倉庫發佈了。
通常是沒必要執行該任務的。
但在升級Nexus時,升級指南有時會包含手動執行該任務的方法。

Update Repositories Index

If files are deployed directly to a repository’s local storage (not deployed through Nexus), you will need to instruct Nexus to update its index. 
When executing this task, Nexus will update its index by first downloading remote indexes (if a proxy repository) and then scan the local storage to index the new files. 
Lastly, the index is published for the repository as well. 
Normally, there should be no need to schedule this task. 
One possible except would be if files are deployed directly to the local storage regularly.
如果把構件直接部署到私服的本地倉庫(而非通過Nexus部署),你需要指導Nexus更新索引。
更新索引時,Nexus將首先下載遠程索引(僅限代理倉庫),然後掃描本地存儲,進而索引新的構件。
最後,索引將隨倉庫發佈。
通常,不需要執行該任務。除非經常有構件被直接部署到本地存儲。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章