I'm having trouble getting an SBT task to run migrations with Flyway; I get an exception when I run the task. Any ideas how I could fix it?
org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: org.postgresql.Driver => Check whether the jar file is present
The following code works, when I run it in BeforeAll, in my tests (ScalaTest), but does not work when I move it into an SBT task.
val flyway = Flyway .configure() .locations("filesystem:./**/resources/db/migrations/") .dataSource("jdbc:postgresql://localhost:5432/my_database", "my_user", "secret") .load() flyway.clean() flyway.migrate() My /build.sbt file looks like this:
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", ) And my /project/build.sbt looks like this:
libraryDependencies ++= List( "org.flywaydb" % "flyway-core" % "7.6.0", "org.postgresql" % "postgresql" % "42.2.19", ) The versions I'm using are:
- SBT: 1.4.5
- Scala: 2.13.4
- Flyway: 7.6.0
Does anyone have any ideas why I'm getting that error, and how I can fix it?
Any help would be greatly appreciated. Thanks :)
https://stackoverflow.com/questions/66512164/pre-test-sbt-task-unable-to-instantiate-jdbc-driver March 07, 2021 at 08:44AM
没有评论:
发表评论