【发布时间】:2021-06-05 07:00:44
【问题描述】:
我在获取 SBT 任务 以使用 Flyway 运行迁移时遇到问题;运行任务时出现异常。有什么想法可以解决吗?
org.flywaydb.core.api.FlywayException: Unable to instance JDBC driver: org.postgresql.Driver => 检查jar文件是否存在
以下代码在我的 测试 (ScalaTest) 中运行 BeforeAll 时有效,但当我将其移至 SBT 任务时无效。
val flyway = Flyway
.configure()
.locations("filesystem:./**/resources/db/migrations/")
.dataSource("jdbc:postgresql://localhost:5432/my_database", "my_user", "secret")
.load()
flyway.clean()
flyway.migrate()
我的/build.sbt 文件如下所示:
import org.flywaydb.core.Flyway
lazy val migrate = taskKey[Unit]("Migrate database")
lazy val migrateTask = Def.task {
println("Migrate")
val flyway = Flyway
.configure()
.locations("filesystem:./**/resources/db/migrations/")
.dataSource("jdbc:postgresql://localhost:5432/my_database", "my_user", "secret")
.load()
flyway.clean()
flyway.migrate()
}
val IntegrationTest = config("integration") extend Test
lazy val integrationTestSettings = inConfig(IntegrationTest)(Defaults.testSettings) ++ List(
IntegrationTest / fork := false,
IntegrationTest / parallelExecution := false,
IntegrationTest / sourceDirectory := baseDirectory.value / "src/test/integration",
IntegrationTest / test := {
(IntegrationTest / test) dependsOn migrateTask
}.value
)
lazy val root = Project(id = "hello", base = file("."))
.configs(Configs.all: _*)
.settings(
integrationTestSettings,
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.4",
)
而我的/project/build.sbt 看起来像这样:
libraryDependencies ++= List(
"org.flywaydb" % "flyway-core" % "7.6.0",
"org.postgresql" % "postgresql" % "42.2.19",
)
我使用的版本是:
- SBT:1.4.5
- 斯卡拉:2.13.4
- 飞行路线:7.6.0
有没有人知道我为什么会收到这个错误,以及如何解决它?
任何帮助将不胜感激。谢谢:)
【问题讨论】:
标签: postgresql scala sbt flyway