SBT无法解决对没有IVY(仅POM)的插件的依赖性

时间:2018-06-27 18:07:10

标签: scala proxy sbt repository

我在公司代理后面工作,因此我正在使用proxy repositories。它工作正常,但仅适用于build.sbt中定义的依赖项。对于插件所需的依赖项(用addSbtPlugin声明),代理存储库仅在依赖项具有ivy.xml的情况下有效。如果仅由*.pom个文件定义,则无法解析,例如com.eed3si9n:sbt-assembly插件的传递依赖项:

[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: org.scalactic#scalactic_2.12;3.0.1: Resolution failed several times for dependency: org.scalactic#scalactic_2.12;3.0.1 {compile=
[default(compile)]}::
[warn]  typesafe-ivy-releases: unable to get resource for org.scalactic#scalactic_2.12;3.0.1: res=https://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalactic_2.12/3.0.1/ivys/ivy.xml: java.net.UnknownHostException: repo.typesafe.com
[warn]  sbt-plugin-releases: unable to get resource for org.scalactic#scalactic_2.12;3.0.1: res=https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.scalactic/scalactic_2.12/3.0.1/ivys/ivy.xml: java.net.UnknownHostException: repo.scala-sbt.org
[warn]  typesafe-ivy-releases: unable to get resource for org.scalactic#scalactic_2.12;3.0.1: res=https://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalactic_2.12/3.0.1/bundles/scalactic_2.12.jar: java.net.UnknownHostException: repo.typesafe.com
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::

[warn]  Note: Unresolved dependencies path:
[warn]          org.scalactic:scalactic_2.12:3.0.1
[warn]            +- com.eed3si9n:sbt-assembly:0.14.6 (scalaVersion=2.12, sbtVersion=1.0) (C:\<path to the project>\project\assembly.sbt#L1-2)

SBT在org.scalactic中创建.ivy2/cache目录,并添加两个文件:

.ivy2/cache
        |___org.scalactic
                   |___scalactic_2.12
                                |___ivy-3.0.1.xml.original
                                |___ivydata-3.0.1.properties

SBT可能会生成该文件,因为在存储库中只有以下内容:

scalactic_2.12-3.0.1-javadoc.jar           10-Nov-2016 00:50  1.82 MB
scalactic_2.12-3.0.1-javadoc.jar.asc->         -    -
scalactic_2.12-3.0.1-javadoc.jar.asc.md5->     -    -
scalactic_2.12-3.0.1-javadoc.jar.asc.sha1->    -    -
scalactic_2.12-3.0.1-javadoc.jar.md5       10-Nov-2016 00:50  32 bytes
scalactic_2.12-3.0.1-javadoc.jar.sha1      10-Nov-2016 00:50  40 bytes
scalactic_2.12-3.0.1-sources.jar           10-Nov-2016 00:50  196.37 KB
scalactic_2.12-3.0.1-sources.jar.asc->         -    -
scalactic_2.12-3.0.1-sources.jar.asc.md5->     -    -
scalactic_2.12-3.0.1-sources.jar.asc.sha1->    -    -
scalactic_2.12-3.0.1-sources.jar.md5       10-Nov-2016 00:50  32 bytes
scalactic_2.12-3.0.1-sources.jar.sha1      10-Nov-2016 00:50  40 bytes
scalactic_2.12-3.0.1.jar                   10-Nov-2016 00:50  689.03 KB
scalactic_2.12-3.0.1.jar.asc->                 -    -
scalactic_2.12-3.0.1.jar.asc.md5->             -    -
scalactic_2.12-3.0.1.jar.asc.sha1->            -    -
scalactic_2.12-3.0.1.jar.md5               10-Nov-2016 00:50  32 bytes
scalactic_2.12-3.0.1.jar.sha1              10-Nov-2016 00:50  40 bytes
scalactic_2.12-3.0.1.pom                   10-Nov-2016 00:50  2.18 KB
scalactic_2.12-3.0.1.pom.asc->                 -    -
scalactic_2.12-3.0.1.pom.asc.md5->             -    -
scalactic_2.12-3.0.1.pom.asc.sha1->            -    -
scalactic_2.12-3.0.1.pom.md5               10-Nov-2016 00:50  32 bytes
scalactic_2.12-3.0.1.pom.sha1              10-Nov-2016 00:50  40 bytes

我们可以看到SBT读取了*.pom文件,但是却做了一些奇怪的事情:

(注意:maven-centralrepositories文件中为模式指定的名称)

tried http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.pom
maven-central: found md file for org.scalactic#scalactic_2.12;3.0.1
    => http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.pom (3.0.1)
downloading http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.pom ...
maven-central: downloading http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.pom
maven-central: downloading http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.pom.sha1
sha1 OK for http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.pom
[SUCCESSFUL ] org.scalactic#scalactic_2.12;3.0.1!scalactic_2.12.pom(pom.original) (330ms)
    tried https://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalactic_2.12/3.0.1/bundles/scalactic_2.12.jar
problem occurred while resolving dependency: org.scalactic#scalactic_2.12;3.0.1 {compile=[default(compile)]} with maven-central: java.lang.RuntimeException: typesafe-ivy-releases: unable to get resource for org.scalactic#scalactic_2.12;3.0.1: res=https://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalactic_2.12/3.0.1/bundles/scalactic_2.12.jar: java.net.UnknownHostException: repo.typesafe.com

最终失败:

[error]         typesafe-ivy-releases: unable to get resource for org.scalactic#scalactic_2.12;3.0.1: res=https://repo.typesafe.com/typesafe/ivy-releases/org.scalactic/scalactic_2.12/3.0.1/bundles/scalactic_2.12.jar: java.net.UnknownHostException: repo.typesafe.com
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

无法启动(ignore无济于事)。

我有一种解决方法:

  • build.sbt
  • 中声明失败的依赖关系
  • 添加一些使用依赖项的伪代码
  • 致电sbt compile

通过这种方式可以解决依赖关系并将其存储到.ivy2/cache

[info] downloading http://<path to repository>/artifactory/maven-central/org/scalactic/scalactic_2.12/3.0.1/scalactic_2.12-3.0.1.jar ...
[info]  [SUCCESSFUL ] org.scalactic#scalactic_2.12;3.0.1!scalactic_2.12.jar(bundle) (1138ms)
[info] Done updating.

然后我删除了伪代码,它基于缓存的依赖项工作。出于明显的原因,我不喜欢这种“解决方案”。

如果有人可以回答我的问题,我将不胜感激:

  1. 为什么相同的依赖项无法为插件解决,但在编译时得到解决?
  2. 有没有一种方法可以告诉SBT不用寻找ivy.xml就解决依赖关系(与编译时一样)?

非常感谢!

0 个答案:

没有答案