如何使用 SBT 将 MATSim 添加到我的 Scala 项目中?

Posted

技术标签:

【中文标题】如何使用 SBT 将 MATSim 添加到我的 Scala 项目中?【英文标题】:How to add MATSim to my Scala project using SBT? 【发布时间】:2021-12-22 23:40:39 【问题描述】:

我正在尝试将 MATSim 与 Scala 和 SBT 一起使用。但是,我不能在没有编译错误的情况下添加依赖项。 MATSim 使用 Maven,但我想将它添加到我的 SBT 项目中。这是我的 build.sbt。

name := "matsim-console"

version := "0.1"

scalaVersion := "2.13.7"

lazy val matsimVersion = "13.0"

resolvers += "osgeo" at "https://repo.osgeo.org/repository/release/"
resolvers += "matsim" at "https://repo.matsim.org/repository/matsim"
resolvers += "jogl" at "https://dl.bintray.com/matsim/matsim/"
resolvers += Resolver.url("jogl1", url("https://mvnrepository.com/artifact/"))( Patterns("[organisation]/[module]/[revision]/[artifact].[ext]") )

lazy val proj = (project in file("."))
  .settings(
    libraryDependencies += "org.jogamp.jogl" % "jogl-all" % "2.4.0-matsim-1",
    libraryDependencies += "org.jogamp.gluegen" % "gluegen-rt" % "2.3.2",
    libraryDependencies += "org.matsim" % "matsim" % matsimVersion,
    libraryDependencies += "org.matsim.contrib" % "vsp" % matsimVersion,
  )

1- 为什么我需要将jog-allgluegen-rt的依赖添加到我的Scala项目中? SBT 不应该导入 MATSim 及其所有依赖项吗?

2- 为什么最后一个依赖项不起作用?我收到此错误:

[error] stack trace is suppressed; run last update for the full output
[error] (update) lmcoursier.internal.shaded.coursier.error.FetchError$DownloadingArtifacts: Error fetching artifacts:
[error] https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-solaris-amd64.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-solaris-amd64.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-android-armv6.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-android-armv6.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-linux-armv6.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-linux-armv6.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-solaris-i586.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-solaris-i586.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-android-armv6.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-android-armv6.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-linux-armv6hf.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-linux-armv6hf.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-linux-armv6.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-linux-armv6.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-linux-armv6hf.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-linux-armv6hf.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-android-aarch64.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-android-aarch64.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-solaris-i586.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-solaris-i586.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-android-aarch64.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/jogl/jogl-all/2.4.0-matsim-1/jogl-all-2.4.0-matsim-1-natives-android-aarch64.jar
[error] https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-solaris-amd64.jar: not found: https://repo.matsim.org/repository/matsim/org/jogamp/gluegen/gluegen-rt/2.4.0-matsim-1/gluegen-rt-2.4.0-matsim-1-natives-solaris-amd64.jar

【问题讨论】:

【参考方案1】:

为什么我需要在我的Scala项目中添加jog-all和gluegen-rt的依赖? SBT 不应该导入 MatSim 及其所有依赖项吗?

没错。你不需要,这就是像 SBT 这样的依赖管理工具的目的。直接添加你需要的依赖,传递依赖会自动拉取。

为什么最后一个依赖项不起作用?我收到此错误

因为它以某种方式寻找不存在的依赖项(或至少不在您提供的存储库中)。

您应该使用sbt dependencyTree(或变体)来更好地了解依赖关系并了解为什么需要这种依赖关系。

【讨论】:

【参考方案2】:

当我切换到 Java 11 时,它应该正常工作。

【讨论】:

您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。

以上是关于如何使用 SBT 将 MATSim 添加到我的 Scala 项目中?的主要内容,如果未能解决你的问题,请参考以下文章

将 Play JSON 库添加到 sbt

sbt / maven是否包含jar文件中的完整依赖项?

如何解决具有不同包装常春藤类型的sbt中的依赖关系?

使用 akka-http 模板的新 sbt 应用程序,如何确定解析器并添加 maven Central?

如何使用 sbt-native-packager 创建 Upstart Zip 包?

如何将插件作为库添加到我制作的插件中?