如何在SBT下载罐子时显示下载进度?

时间:2014-12-27 12:49:20

标签: java scala sbt ivy

当我使用SBT打包我的应用程序时,从中央maven存储库或Typesafe repo获取jar可能需要很长时间。对我来说,确定下载时是否卡住会很痛苦。例如,

$ sbt package
[info] Loading project definition from /home/au9ustine/projects/gloin/project
[info] Set current project to gloin (in build file:/home/au9ustine/projects/gloin/)
...
[info] downloading https://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.10.3/scala-compiler-2.10.3.jar

偶尔会有很长一段时间。

我搜索了很多,发现它在连接问题上遇到了问题。但是目前我不知道如何识别问题何时发生,因为有时连接效果很好。所以,我需要检查下载文件的进度。 wget之类的内容提供了:

$ wget -c http://www.sonatype.org/downloads/nexus-latest-bundle.zip
--2014-12-27 20:00:28--  http://www.sonatype.org/downloads/nexus-latest-bundle.zip
Resolving www.sonatype.org (www.sonatype.org)... 54.85.199.48, 54.165.51.98
Connecting to www.sonatype.org (www.sonatype.org)|54.85.199.48|:80... connected.
...
HTTP request sent, awaiting response... 200 OK
Length: 80393206 (77M) [application/zip]
Saving to: ‘nexus-latest-bundle.zip’

nexus-latest-bundle 100%[=====================>]  76.67M  67.6KB/s   in 17m 6s

2014-12-27 20:17:41 (76.5 KB/s) - ‘nexus-latest-bundle.zip’ saved [80393206/80393206]

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:2)

Apache Ivy对此负责,可以使用showprogress ant-task的resolver属性来管理Ivy:

http://ant.apache.org/ivy/history/2.3.0/use/resolve.html

但是sbt直接使用Ivy API,showprogress似乎被硬编码为false。但是,实现您想要的方法有一个棘手的方法:您可以实现自己的MessageLogger,而不是this(请参阅isShowProgress)。到"注册"它,从IvySbtwithIvy类重新定义CachedResolutionResolveEngine

def withIvy[T](log: Logger)(f: Ivy => T): T =
       withIvy(new YourLoggerInterface(log))(f)

IvySbt类是最终的,CachedResolutionResolveEngine是私有的,因此您应该使用dynamic proxy来挂钩withIvy(这非常简单)。当我玩依赖解析时,至少类似的解决方案对我有用。但它当然不太安全。

还有一种方法可以在ivy.xmlivysettings.xmlHow to use SBT with external ivy configuration)中定义此类属性

相关问题