向 SBT 项目添加 Maven 依赖项

Add a maven dependency to SBT project

我试图在我的 build.sbt 文件中引用 Maven 项目依赖项。我知道我需要在我的文件中添加一个额外的 resolver,因为该项目托管在一个内部人工制品商店中

build.sbt

libraryDependencies ++= Seq(
  "org.apache.spark" %% "spark-core" % "2.4.4",
  "org.apache.spark" %% "spark-sql" % "2.4.4",
  "com.<companyname>" %% "<libraryname>" % "2.3.0"
)

resolvers += "<library name>" at "http://artifactory.<internal url>.io:80/dsc-mvn"

然而,事实证明,SBT 最终会搜索附加了 _2.11 版本的路径。这是我在 IntelliJ

中看到的错误消息
[info] Loading settings for project sbt-demo from build.sbt ...
[warn] Discarding 1 session setting.  Use 'session save' to persist session settings.
[info] Set current project to SparkExample (in build file:<project_path>)
[info] Defining Global / sbtStructureOptions
[info] The new value will be used by Global / ssOptions
[info] Reapplying settings...
[info] Set current project to SparkExample (in build file:<project_path>)
[info] Updating ...
[warn]  module not found: com.<companyname>#<libraryname>_2.11;2.3.0
[warn] ==== local: tried
[warn]   /Users/vshah/.ivy2/local/com.<companyname>/<libraryname>_2.11/2.3.0/ivys/ivy.xml
[warn] ==== public: tried
[warn]   https://repo1.maven.org/maven2/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom
[warn] ==== local-preloaded-ivy: tried
[warn]   /Users/vshah/.sbt/preloaded/com.<companyname>/<libraryname>_2.11/2.3.0/ivys/ivy.xml
[warn] ==== local-preloaded: tried
[warn]   file:////Users/vshah/.sbt/preloaded/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom
[warn] ==== <libraryname>: tried
[warn]   http://artifactory.<internal url>.io:80/dsc-mvn/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  ::          UNRESOLVED DEPENDENCIES         ::
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]  :: com.<companyname>#<libraryname>_2.11;2.3.0: not found
[warn]  ::::::::::::::::::::::::::::::::::::::::::::::
[warn]

无效路径(因为项目正在尝试在上面搜索)- http://artifactory.<internal url>.io/dsc-mvn/com/<companyname>/<libraryname>_2.11/2.3.0/<libraryname>_2.11-2.3.0.pom

有效路径 - http://artifactory.<internal url>.io/dsc-mvn/com/<companyname>/<libraryname>/2.3.0/<libraryname>_2.11-2.3.0.pom

我的问题是如何让 SBT 知道我在上述有效路径中引用了一个 Maven 项目?

参考https://mvnrepository.com/artifact/org.scala-sbt为您的项目获取正确的构建工具,并请检查依赖项中的版本是否与您的 scala 版本匹配。

能否详细介绍一下您需要的依赖类型?

这应该有效:

"com.<companyname>" % "<libraryname>" % "2.3.0"

定义中的%%自动将项目scala版本附加到库名称。查看 official sbt documentation 了解更多信息。