Sbt can't authorize in Artifactory

2019-07-07 01:53发布

问题:

I'm behind corporate proxy server with domain authorization. There is Artifactory in the company and one should use domain credentials to login in it. When I try to run sbt in my Play! project folder I get next output:

j:\Education\Scala\taxi\sources\branches\dev>sbt
[info] Loading project definition from J:\Education\Scala\taxi\sources\branches\dev\project
[info] Updating {file:/J:/Education/Scala/taxi/sources/branches/dev/project/}dev-build...
[info] Resolving com.typesafe.play#sbt-plugin;2.3.7 ...
[info] Resolving com.typesafe.play#sbt-plugin;2.3.7 ...
[error] Server access Error: Connection timed out: connect url=https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.play/sbt-plugin/scala_2.10/sbt_0.13/2.3.7/ivys/ivy.xml
[error] Server access Error: Connection timed out: connect url=https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.play/sbt-plugin/scala_2.10/sbt_0.13/2.3.7/ivys/ivy.xml
[error] Unable to find credentials for [Artifactory Realm @ artifactory.lab.croc.ru].
[error] Unable to find credentials for [Artifactory Realm @ artifactory.lab.croc.ru].
[error] Unable to find credentials for [Artifactory Realm @ artifactory.lab.croc.ru].
[warn]  module not found: com.typesafe.play#sbt-plugin;2.3.7
[warn] ==== typesafe-ivy-releases: tried
[warn]   https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.play/sbt-plugin/scala_2.10/sbt_0.13/2.3.7/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.play/sbt-plugin/scala_2.10/sbt_0.13/2.3.7/ivys/ivy.xml
[warn] ==== local: tried
[warn]   C:\Users\AlSedov\.ivy2\local\com.typesafe.play\sbt-plugin\scala_2.10\sbt_0.13\2.3.7\ivys\ivy.xml
[warn] ==== croc-ivy-proxy-libs-release: tried
[warn]   http://artifactory.lab.croc.ru:8081/artifactory/libs-release/com.typesafe.play/sbt-plugin/scala_2.10/sbt_0.13/2.3.7/ivys/ivy.xml
[warn] ==== croc-maven-proxy-libs-release: tried
[warn]   http://artifactory.lab.croc.ru:8081/artifactory/libs-release/com/typesafe/play/sbt-plugin_2.10_0.13/2.3.7/sbt-plugin-2.3.7.pom
[warn] ==== croc-maven-proxy-plugins-release: tried
[warn]   http://artifactory.lab.croc.ru:8081/artifactory/plugins-release/com/typesafe/play/sbt-plugin_2.10_0.13/2.3.7/sbt-plugin-2.3.7.pom
[info] Resolving com.typesafe.sbt#sbt-coffeescript;1.0.0 ...
 [info] Resolving com.typesafe.sbt#sbt-coffeescript;1.0.0 ...
[error] Server access Error: Connection timed out: connect url=https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-coffeescript/scala_2.10/sbt_0.13/1.0.0/ivys/ivy.xml
...

Where

  • croc-ivy-proxy-libs-release, croc-maven-proxy-libs-release, croc-maven-proxy-plugins-release - repositories that is defines in the ~/.sbt/repositories file
  • http://artifactory.lab.croc.ru:8081/artifactory - base address of our Artifactory

As you can see there are couple of requests to typesafe and scala-sbt repos that are failed (but works in browser...). I have no idea where sbt took this addresses. There are no such urls in my project's files. And I don't know why it failed. My thought was it's because of our proxy but I have http_proxy and http_port env variables that are point to company's proxy address.

And the main problem - [error] Unable to find credentials for [Artifactory Realm @ artifactory.lab.croc.ru]. I have all my body hurts from this stuff... There is a credencials file with next content in it:

realm=Artifactory Realm
host=artifactory.lab.croc.ru
user=MyName
password=MyPassword

And there is env variable SBT_CREDENTIALS that contains path to this file (I found this trick in https://github.com/sbt/sbt/blob/0.13/launch/src/main/scala/xsbt/boot/Update.scala, 57). But it's doesn't work still.

Spent two days struggling... crying...

Update

Finally I removed next env variables:

  • http_host
  • http_port
  • java_opts
  • sbt_credentials

, removed ive cache, removed repositories and credentials files, reinstall SBT and made reboot. After that I made next actions:

  1. Run sbt in command line. No effect, thete are timeouts in log.
  2. set java_opts=-Dhttps.proxyHost=proxy.croc.ru -Dhttps.proxyPort=8000 and run sbt. It worked! By default sbt use HTTPS to access repositiroes.
  3. Return back the repositories file that contains base urls of the Artifactory's repositories, it starts from http://. Then change java_opts to set java_opts=-Dhttp.proxyHost=proxy.croc.ru -Dhttp.proxyPort=8000 and run sbt. Errors in log:

try to get credentials for: Artifactory Realm@artifactory.lab.croc.ru authentication: k='Artifactory Realm@artifactory.lab.croc.ru' c='null' HTTP response status: 401 url=http://artifactory.lab.croc.ru:8081/artifactory/libs-release/org.scala-lang/scala-library/2.10.4/ivys/ivy.xml CLIENT ERROR: Unauthorized url=http://artifactory.lab.croc.ru:8081/artifactory/libs-release/org.scala-lang/scala-library/2.10.4/ivys/ivy.xml

  1. Ok, there is no credentials I think. Next, I returned the .credentials file into .sbt folder and 'set sbt_credentials=c:\Users\AlSedov\.sbt\.credentials'. Run sbt again. No effect, the process freezes with no end. And nothing special in the log (btw, it breaks in the middle on a file path)

:: resolving dependencies :: org.scala-sbt#boot-app;1.0 confs: [default] validate = true refresh = false resolving dependencies for configuration 'default' == resolving dependencies for org.scala-sbt#boot-app;1.0 [default] loadData of org.scala-sbt#boot-app;1.0 of rootConf=default == resolving dependencies org.scala-sbt#boot-app;1.0->org.scala-sbt#sbt;0.13.7 [default->default(compile)] loadData of org.scala-sbt#sbt;0.13.7 of rootConf=default using redefined-public to resolve org.scala-sbt#sbt;0.13.7 redefined-public: Checking cache for: dependency: org.scala-sbt#sbt;0.13.7 {default=[default(compile)]} redefined-public: no namespace defined: using system No entry is found in the ModuleDescriptorCache : C:\Users\AlSedov.ivy2\cache\org.scala-sbt\sbt\ivy-0.13.7.xml post 1.3 ivy file: using exact as default matcher found ivy file in cache for org.scala-sbt#sbt;0.13.7 (resolved by redefined-public): C:\Users\AlSedov.ivy2\cache\org.scala-sbt\sbt\ivy-

Update 2

I've tried to `set java_opts=-Dhttp.proxyHost=proxy.croc.ru -Dhttp.proxyPort=8000 -Dhttp.nonProxyHosts=172.'. The Artifactory is in 172. network segment. And it started to work! But very very slowly. I believe that it's because of unnecessary lookups in the Artifactory. I have next content of the repositories file:

[repositories]
local
croc-ivy-proxy-libs-release: http://artifactory.lab.croc.ru:8081/artifactory/libs-release, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
croc-maven-proxy-libs-release: http://artifactory.lab.croc.ru:8081/artifactory/libs-release
croc-maven-proxy-plugins-release: http://artifactory.lab.croc.ru:8081/artifactory/plugins-release

They all use the same Artifactory base address but different formats of an artifact specification. I know almost nothing about Artifactory but what if... When sbt asks for an artifact it uses Ivy-format first. Ok. Imagine the artifact is in an external Maven repository. The result is unnecessary lookups for the artifact in Ivy-format through all external repositories.