有没有办法设置sbt依赖的来源?

时间:2019-06-21 08:54:09

标签: scala maven sbt

由于某种原因,我无法直接访问某些sbt依赖关系,这会导致(部分)错误。

[warn]            +- default:example-build:0.1.0-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0)
[error] sbt.librarymanagement.ResolveException: unresolved dependency: com.typesafe.sbteclipse#sbteclipse-plugin;5.2.4: Resolution failed several times for dependency: com.typesafe.sbteclipse#sbteclipse-plugin;5.2.4 {compile=[default(compile)]}:: 
[error]         typesafe-ivy-releases: unable to get resource for com.typesafe.sbteclipse#sbteclipse-plugin;5.2.4: res=https://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbteclipse/sbteclipse-plugin/scala_2.12/sbt_1.0/5.2.4/ivys/ivy.xml: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

是否有像maven这样的sbt依赖源的配置?

<mirror>
    <id>nexus-aliyun</id>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>
</mirror>

或者如何使用Maven管理sbt的依赖项?

配置

1 个答案:

答案 0 :(得分:0)

不可变的源依赖项:

lazy val scoptJVMRef = ProjectRef(uri("git://github.com/scopt/scopt.git#c744bc48393e21092795059aa925fe50729fe62b"), "scoptJVM")

ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.12.2"

lazy val root = (project in file("."))
  .dependsOn(scoptJVMRef)
  .settings(
    name := "Hello world"
  )

当您启动sbt并运行compile时,sbt会自动在登台目录下克隆scopt / scopt并将构建链接在一起。

这还意味着您的sbt版本需要兼容,并且您最终可能会得到不需要的触发插件。

另一个限制是登台目录在初始克隆后不会更新。

我想要的是一种混合依赖关系,我可以连接多个存储库,并立即进行代码和测试;但是对于发布,请使用Maven二进制文件作为依赖项。

addSbtPlugin("com.eed3si9n" % "sbt-sriracha" % "0.1.0")

然后您可以编写:

lazy val scoptJVMRef = ProjectRef(workspaceDirectory / "scopt", "scoptJVM")
lazy val scoptJVMLib = "com.github.scopt" %% "scopt" % "3.7.0"

lazy val root = (project in file("."))
  .sourceDependency(scoptJVMRef, scoptJVMLib)
  .settings(
    name := "Hello world"
  )

您可以检查一下libraryDependency设置:

$ sbt
sbt:helloworld> libraryDependencies
[info] * org.scala-lang:scala-library:2.12.6
[info] * com.github.scopt:scopt:3.7.0

希望这会有所帮助。如果它不能回答您的问题,或者您有其他意见,请告诉我。祝你好运。