首次使用 SBT - 检索代理背后的依赖项问题
Posted
技术标签:
【中文标题】首次使用 SBT - 检索代理背后的依赖项问题【英文标题】:using SBT for first time - issue retrieving dependencies behind proxy 【发布时间】:2017-09-13 20:16:31 【问题描述】:我已下载 SBT (sbt-0.13.15.zip) 并解压缩,但在运行 sbt.bat 时遇到问题。
最初,当我发现我需要指定 only https 配置而不是 http 配置时,我解决了代理问题 - 当同时提供两者时,它正在使用http,但它失败了。
所以现在我不再有代理问题了,但是在尝试获取 jansi 依赖项时它失败了:
setting 'basedir' to 'C:\Users\vfuchs070114\.sbt\boot'
:: resolving dependencies :: org.scala-sbt#boot-jansi;1.0
confs: [default]
validate = true
refresh = false
resolving dependencies for configuration 'default'
== resolving dependencies for org.scala-sbt#boot-jansi;1.0 [default]
loadData of org.scala-sbt#boot-jansi;1.0 of rootConf=default
== resolving dependencies org.scala-sbt#boot-jansi;1.0->org.fusesource.jansi#jansi;1.11 [default->default(compile)]
loadData of org.fusesource.jansi#jansi;1.11 of rootConf=default
using redefined-public to resolve org.fusesource.jansi#jansi;1.11
redefined-public: Checking cache for: dependency: org.fusesource.jansi#jansi;1.11 default=[default(compile)]
redefined-public: no namespace defined: using system
no ivy file in cache for org.fusesource.jansi#jansi;1.11: tried C:\Users\vfuchs070114\.ivy2\cache\org.fusesource.jansi\jansi\ivy-1.11.xml
redefined-public: no latest strategy defined: using default
local: no namespace defined: using system
no ivy file in cache for org.fusesource.jansi#jansi;1.11: tried C:\Users\vfuchs070114\.ivy2\cache\org.fusesource.jansi\jansi\ivy-1.11.xml
trying C:\Users\vfuchs070114\.ivy2\local\org.fusesource.jansi\jansi\1.11\ivys\ivy.xml
tried C:\Users\vfuchs070114\.ivy2\local\org.fusesource.jansi\jansi\1.11\ivys\ivy.xml
local: resource not reachable for org.fusesource.jansi#jansi;1.11: res=C:\Users\vfuchs070114\.ivy2\local\org.fusesource.jansi\jansi\1.11\ivys\ivy.xml
trying C:\Users\vfuchs070114\.ivy2\local\org.fusesource.jansi\jansi\1.11\jars\jansi.jar
tried C:\Users\vfuchs070114\.ivy2\local\org.fusesource.jansi\jansi\1.11\jars\jansi.jar
local: resource not reachable for org.fusesource.jansi#jansi;1.11: res=C:\Users\vfuchs070114\.ivy2\local\org.fusesource.jansi\jansi\1.11\jars\jansi.jar
local: no ivy file nor artifact found for org.fusesource.jansi#jansi;1.11
local-preloaded-ivy: no namespace defined: using system
no ivy file in cache for org.fusesource.jansi#jansi;1.11: tried C:\Users\vfuchs070114\.ivy2\cache\org.fusesource.jansi\jansi\ivy-1.11.xml
trying file:/C:/Users/vfuchs070114/.sbt/preloaded/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml
tried file:/C:/Users/vfuchs070114/.sbt/preloaded/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml
local-preloaded-ivy: resource not reachable for org.fusesource.jansi#jansi;1.11: res=file:/C:/Users/vfuchs070114/.sbt/preloaded/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml
local-preloaded-ivy: no ivy file found for org.fusesource.jansi#jansi;1.11
local-preloaded: no namespace defined: using system
no ivy file in cache for org.fusesource.jansi#jansi;1.11: tried C:\Users\vfuchs070114\.ivy2\cache\org.fusesource.jansi\jansi\ivy-1.11.xml
trying file:/C:/Users/vfuchs070114/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom
tried file:/C:/Users/vfuchs070114/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom
local-preloaded: resource not reachable for org/fusesource/jansi#jansi;1.11: res=file:/C:/Users/vfuchs070114/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom
trying file:/C:/Users/vfuchs070114/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar
tried file:/C:/Users/vfuchs070114/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar
local-preloaded: resource not reachable for org/fusesource/jansi#jansi;1.11: res=file:/C:/Users/vfuchs070114/.sbt/preloaded/org/fusesource/jansi/jansi/1.11/jansi-1.11.jar
local-preloaded: no ivy file nor artifact found for org.fusesource.jansi#jansi;1.11
Maven Central: no namespace defined: using system
no ivy file in cache for org.fusesource.jansi#jansi;1.11: tried C:\Users\vfuchs070114\.ivy2\cache\org.fusesource.jansi\jansi\ivy-1.11.xml
trying https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom
tried https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom
problem occurred while resolving dependency: org.fusesource.jansi#jansi;1.11 default=[default(compile)] with Maven Central: java.lang.RuntimeException: java.util.NoSuchElementException
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1453)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:2965)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:489)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at org.apache.ivy.util.url.BasicURLHandler.checkStatusCode(BasicURLHandler.java:130)
at org.apache.ivy.util.url.BasicURLHandler.getURLInfo$57a0216e(BasicURLHandler.java:73)
at org.apache.ivy.util.url.BasicURLHandler.getURLInfo(BasicURLHandler.java:54)
at org.apache.ivy.plugins.repository.url.URLResource.init(URLResource.java:65)
at org.apache.ivy.plugins.repository.url.URLResource.exists(URLResource.java:81)
at org.apache.ivy.plugins.resolver.RepositoryResolver.findResourceUsingPattern(RepositoryResolver.java:97)
at org.apache.ivy.plugins.resolver.AbstractPatternsBasedResolver.findResourceUsingPatterns(AbstractPatternsBasedResolver.java:96)
at org.apache.ivy.plugins.resolver.IBiblioResolver.findIvyFileRef(IBiblioResolver.java:102)
at org.apache.ivy.plugins.resolver.BasicResolver.getDependency(BasicResolver.java:228)
at org.apache.ivy.plugins.resolver.IBiblioResolver.getDependency(IBiblioResolver.java:512)
at org.apache.ivy.plugins.resolver.ChainResolver.getDependency(ChainResolver.java:104)
at org.apache.ivy.core.resolve.IvyNode.loadData(IvyNode.java:169)
at org.apache.ivy.core.resolve.VisitNode.loadData(VisitNode.java:292)
at org.apache.ivy.core.resolve.ResolveEngine.fetchDependencies(ResolveEngine.java:714)
at org.apache.ivy.core.resolve.ResolveEngine.doFetchDependencies(ResolveEngine.java:799)
at org.apache.ivy.core.resolve.ResolveEngine.fetchDependencies(ResolveEngine.java:722)
at org.apache.ivy.core.resolve.ResolveEngine.getDependencies(ResolveEngine.java:594)
at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:234)
at xsbt.boot.Update.xsbt$boot$Update$$lockedApply(Update.scala:105)
at xsbt.boot.Update$$anon$4.call(Update.scala:99)
at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93)
at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78)
at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97)
at xsbt.boot.Using$.withResource(Using.scala:10)
at xsbt.boot.Using$.apply(Using.scala:9)
at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58)
at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48)
at xsbt.boot.Locks$.apply0(Locks.scala:31)
at xsbt.boot.Locks$.apply(Locks.scala:28)
at xsbt.boot.Update.apply(Update.scala:100)
at xsbt.boot.Launch.update(Launch.scala:352)
at xsbt.boot.Launch$$anonfun$jansiLoader$1.apply(Launch.scala:178)
at scala.Option.getOrElse(Option.scala:120)
at xsbt.boot.Launch.jansiLoader$2f324eef(Launch.scala:173)
at xsbt.boot.Launch.<init>(Launch.scala:150)
at xsbt.boot.Launcher$.apply(Launch.scala:366)
at xsbt.boot.Launch$.apply(Launch.scala:18)
at xsbt.boot.Boot$.runImpl(Boot.scala:41)
at xsbt.boot.Boot$.main(Boot.scala:17)
at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:349)
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2016)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1511)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
... 41 more
它试图从存在的https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.11/jansi-1.11.pom 获取数据,但它似乎无法解析它或其他东西(StringTokenizer 抛出的 NoSuchElementException)。我试图将 pom 和 jar 文件放在它尝试的本地找到它们:它找到了它们,但最后并没有太大的不同。
typesafe-ivy-releases 和 sbt-ivy-snapshots 也会发生类似的情况,它试图从不存在的远程 URL 获取一些 ivy 信息:
https://repo.typesafe.com/typesafe/ivy-releases/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml
https://repo.scala-sbt.org/scalasbt/ivy-snapshots/org.fusesource.jansi/jansi/1.11/ivys/ivy.xml
因此,在这种情况下,失败并不令人意外。
知道什么可能是错的吗?
谢谢
============
编辑
我在这里看到https://github.com/typesafehub/activator/issues/18,这可能是 Ipv4 / Ipv6 的问题。我尝试添加推荐的属性以强制 IPv4 (-Djava.net.preferIPv4Stack=true),但它仍然不起作用。
但是,我感觉根本原因可能是这样的,或者某些编码问题,导致远程文件“无法解析”
编辑 2
昨天我花了一整天的时间手动获取依赖项,最后它仍然无法正常工作。然后我在家里的电脑上尝试了没有代理的情况,它运行良好。所以现在我再次尝试,只专注于运行 sbt.bat:我在 sbt.bat 中添加了一个“echo”,就在 java 调用之前,以确保它符合我的期望,并且确实如此:
"C:\Toolbox\apps\jdk\jdk1.8.0_25-windows-x64\bin\java.exe" -Dhttps.proxyHost=theProxyURL
-Dhttps.proxyPort=8080 -Dhttps.proxyUser=myId -Dhttps.proxyPassword=myPassword
-cp "C:\Toolbox\apps\sbt-0.13.15_2ndTry\bin\sbt-launch.jar" xsbt.boot.Boot
但我仍然遇到问题.. 如果是证书问题或类似问题,我应该得到更清晰的消息,对吗?
编辑 3
我观察到的是,即使代理配置不正确,我们也不会在日志中收到任何相关消息。例如,通过故意提供不正确的代理设置(例如不存在的代理主机),我们不会得到与配置正确值时不同的消息。这使得调试非常不方便。
我发现的另一个问题是,即使正确配置密码,当密码包含感叹号时,修改后的版本也可能会传递给 SBT 启动器。我为此创建了一个问题:https://github.com/sbt/sbt/issues/3139。但即使解决了这个问题,我仍然面临问题。
实际上有几个代理相关的未解决问题:https://github.com/sbt/sbt/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20proxy
我现在正在寻找的一件事是配置代理存储库:http://www.scala-sbt.org/0.13/docs/Proxy-Repositories.html(我们使用 Nexus)
【问题讨论】:
How to use sbt from behind proxy?的可能重复 【参考方案1】:尽管我无法找到最初问题的明确答案,但我学到了一些东西:
在企业互联网代理后面使用 SBT 的解决方法是使用内部 Nexus 代理:Why is sbt trying to download non-existing dependencies?
SBT 日志记录不是很有帮助,同样的错误消息可能有几十个失败的实际原因。
根据配置的依赖库 (http://www.scala-sbt.org/0.13/docs/Proxy-Repositories.html),SBT 将根据各种命名约定(Ivy 和 Maven)尝试各种 UR。这就是为什么有时 URL 根本不存在的原因。
【讨论】:
【参考方案2】:如果您在代理后面(企业网络) 对于窗户: 在 sbt 安装文件夹中,进入 conf/sbtconfig.txt 文件只需添加以下行并保存并尝试。
-Dhttp.proxyHost=proxy
-Dhttp.proxyPort=portno
-Dhttp.proxyUser=UserId
-Dhttp.proxyPassword=Password
-Dhttps.proxyHost=proxyhost
-Dhttps.proxyPort=portno
-Dhttps.proxyUser=UserId
-Dhttps.proxyPassword=Password
对于 Linux/Unix:
export JAVA_OPTS="$JAVA_OPTS -Dhttp.proxyHost=proxyHost -Dhttp.proxyPort=proxyPortNumber -Dhttp.proxyUser=UserId -Dhttp.proxyPassword=Password -Dhttps.proxyHost=proxyHost -Dhttps.proxyPort=proxyPortNumber -Dhttps.proxyUser=UserId -Dhttps.proxyPassword=Password"
它对我有用。
【讨论】:
【参考方案3】:确保在执行 sbt 构建的盒子上没有设置任何代理环境变量(http_proxy, https_proxy
等)。根据我的经验,如果您将 SBT 设置为通过 https(例如 Nexus)从代理存储库下载依赖项并同时设置 https_proxy
env var,则它可能会出现问题。正如docs 中解释的那样,这些代理设置是由 SBT 自动获取的,所以在运行 sbt 构建之前,unset https_proxy
首先是。
【讨论】:
【参考方案4】:对于那些使用企业代理并且仍在尝试弄清楚如何在 IntelliJ 中设置 HTTP 代理的人来说,这对我有用。我希望这可以帮助像我一样刚接触 IntelliJ 的其他人。
(注意:在相应的框中指定您的网络用户名和密码):-
【讨论】:
以上是关于首次使用 SBT - 检索代理背后的依赖项问题的主要内容,如果未能解决你的问题,请参考以下文章