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将首先下载远程索引(仅限代理仓库),然后扫描本地存储,进而索引新的构件。
最后,索引将随仓库发布。
通常,不需要执行该任务。除非经常有构件被直接部署到本地存储。
相关文章
相关标签/搜索