尝试使用 sbt 导入 dbcp2 和 postgres 库时出错 [重复]

Posted

技术标签:

【中文标题】尝试使用 sbt 导入 dbcp2 和 postgres 库时出错 [重复]【英文标题】:Error when trying to import the dbcp2 and postgres library with sbt [duplicate] 【发布时间】:2021-08-13 02:50:19 【问题描述】:

我有以下 sbt 文件:

name := "data-test"

version := "0.1"

scalaVersion := "2.12.5"
libraryDependencies ++= 
  val sparkVersion = "3.1.1"
  val cassandraVersion = "3.0.1"
  val dbcp2Version = "2.8.0"
  val postgresqlVersion = "42.2.20"
  Seq( "org.apache.spark" %% "spark-core" % sparkVersion,
    "org.apache.spark" %% "spark-streaming" % sparkVersion,
    "org.apache.spark" %% "spark-sql" % sparkVersion,
    "org.apache.spark" %% "spark-streaming-kafka-0-10" % sparkVersion,
    "com.datastax.spark" %% "spark-cassandra-connector" % cassandraVersion,
    "org.apache.spark" %% "spark-sql-kafka-0-10" % sparkVersion,
    "org.apache.commons" %% "commons-dbcp2" % dbcp2Version,
    "org.postgresql" %% "postgresql" % postgresqlVersion
  )

每当我尝试重新加载 sbt 时,我都会在尝试下载 dbcp 和 postgres 的依赖项时收到错误消息。当我在没有这两个库的情况下执行相同的过程时,sbt reload 成功结束。

这样的错误:

[warn]  Note: Unresolved dependencies path:
[error] stack trace is suppressed; run 'last update' for the full output
[error] stack trace is suppressed; run 'last ssExtractDependencies' for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.apache.commons:commons-dbcp2_2.12:2.8.0
[error]   Not found
[error]   Not found
[error]   not found: C:\Users\danilo.rodrigues\.ivy2\localorg.apache.commons\commons-dbcp2_2.12\2.8.0\ivys\ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/apache/commons/commons-dbcp2_2.12/2.8.0/commons-dbcp2_2.12-2.8.0.pom
[error] Error downloading org.postgresql:postgresql_2.12:42.2.20
[error]   Not found
[error]   Not found
[error]   not found: C:\Users\danilo.rodrigues\.ivy2\localorg.postgresql\postgresql_2.12\42.2.20\ivys\ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/postgresql/postgresql_2.12/42.2.20/postgresql_2.12-42.2.20.pom
[error] (ssExtractDependencies) sbt.librarymanagement.ResolveException: Error downloading org.apache.commons:commons-dbcp2_2.12:2.8.0
[error]   Not found
[error]   Not found
[error]   not found: C:\Users\danilo.rodrigues\.ivy2\localorg.apache.commons\commons-dbcp2_2.12\2.8.0\ivys\ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/apache/commons/commons-dbcp2_2.12/2.8.0/commons-dbcp2_2.12-2.8.0.pom
[error] Error downloading org.postgresql:postgresql_2.12:42.2.20
[error]   Not found
[error]   Not found
[error]   not found: C:\Users\danilo.rodrigues\.ivy2\localorg.postgresql\postgresql_2.12\42.2.20\ivys\ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/postgresql/postgresql_2.12/42.2.20/postgresql_2.12-42.2.20.pom
[error] Total time: 6 s, completed 24 de mai de 2021 16:28:53
[info] shutting down sbt server

有人可以帮我吗?

【问题讨论】:

【参考方案1】:

快速回答:不要将%% 用于Java 库,而应使用%

%% 用于在库名称中自动附加 Scala 版本,这可以在您的错误消息 Error downloading org.apache.commons:commons-dbcp2_2.12:2.8.0 中看到,其中附加了后缀 _2.12

更多详情Build.scala, % and %% symbols meaning

【讨论】:

以上是关于尝试使用 sbt 导入 dbcp2 和 postgres 库时出错 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

导入SBT项目时出错

为 apache phoenix 导入 sbt 项目时出错

导入 sbt 项目时出错:idea

SBT 的依赖问题

Intellij 无法导入 SBT 项目

播放框架 SBT 导入 play.api.libs.streams