Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Configuration failing for Postgresql #15

Open
binshi opened this issue Feb 22, 2018 · 3 comments
Open

Custom Configuration failing for Postgresql #15

binshi opened this issue Feb 22, 2018 · 3 comments

Comments

@binshi
Copy link

binshi commented Feb 22, 2018

Postgresql configuration works fine with normal flyway configuration but fails with custom configurations as below:

I am running it using: sbt app/prod:flywayInfo

enablePlugins(FlywayPlugin)

lazy val CustomConfig = config("custom") describedAs "A custom config." extend Runtime

lazy val customSettings: Seq[Def.Setting[_]] = Seq(
  flywayUser := "customUser",
  flywayPassword := "customPassword",
  flywayUrl := "jdbc:postgresql://host:port/db",
  flywayLocations += "db/migration"
)

// flywayBaseSettings(CustomConfig) doesnt work and is replaced by flywayBaseSettings(Runtime)
lazy val app = (project in file("app")).
  settings(inConfig(CustomConfig)(FlywayPlugin.flywayBaseSettings(Runtime) ++ customSettings): _*)

The custom configuration keeps failing for postgresql driver. Below is the stacktrace

org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: org.postgresql.Driver => Check whether the jar file is present
[error]         at org.flywaydb.core.internal.util.jdbc.DriverDataSource.<init>(DriverDataSource.java:136)
[error]         at org.flywaydb.core.Flyway.configure(Flyway.java:1435)
[error]         at org.flywaydb.core.Flyway.configure(Flyway.java:1414)
[error]         at io.github.davidmweber.FlywayPlugin$FlywayOps$.configureSysProps$extension(FlywayPlugin.scala:295)
[error]         at io.github.davidmweber.FlywayPlugin$FlywayOps$.configure$extension0(FlywayPlugin.scala:239)
[error]         at io.github.davidmweber.FlywayPlugin$Flyway$.apply(FlywayPlugin.scala:219)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$48(FlywayPlugin.scala:181)
[error]         at io.github.davidmweber.FlywayPlugin$.withContextClassLoader(FlywayPlugin.scala:210)
[error]         at io.github.davidmweber.FlywayPlugin$.withPrepared(FlywayPlugin.scala:193)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$47(FlywayPlugin.scala:180)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$47$adapted(FlywayPlugin.scala:180)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] Caused by: org.flywaydb.core.api.FlywayException: Unable to instantiate class org.postgresql.Driver : org.postgresql.Driver
[error]         at org.flywaydb.core.internal.util.ClassUtils.instantiate(ClassUtils.java:61)
[error]         at org.flywaydb.core.internal.util.jdbc.DriverDataSource.<init>(DriverDataSource.java:132)
[error]         at org.flywaydb.core.Flyway.configure(Flyway.java:1435)
[error]         at org.flywaydb.core.Flyway.configure(Flyway.java:1414)
[error]         at io.github.davidmweber.FlywayPlugin$FlywayOps$.configureSysProps$extension(FlywayPlugin.scala:295)
[error]         at io.github.davidmweber.FlywayPlugin$FlywayOps$.configure$extension0(FlywayPlugin.scala:239)
[error]         at io.github.davidmweber.FlywayPlugin$Flyway$.apply(FlywayPlugin.scala:219)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$48(FlywayPlugin.scala:181)
[error]         at io.github.davidmweber.FlywayPlugin$.withContextClassLoader(FlywayPlugin.scala:210)
[error]         at io.github.davidmweber.FlywayPlugin$.withPrepared(FlywayPlugin.scala:193)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$47(FlywayPlugin.scala:180)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$47$adapted(FlywayPlugin.scala:180)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
[error]         at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[error]         at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error]         at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error]         at java.lang.Class.forName0(Native Method)
[error]         at java.lang.Class.forName(Class.java:348)
[error]         at org.flywaydb.core.internal.util.ClassUtils.instantiate(ClassUtils.java:59)
[error]         at org.flywaydb.core.internal.util.jdbc.DriverDataSource.<init>(DriverDataSource.java:132)
[error]         at org.flywaydb.core.Flyway.configure(Flyway.java:1435)
[error]         at org.flywaydb.core.Flyway.configure(Flyway.java:1414)
[error]         at io.github.davidmweber.FlywayPlugin$FlywayOps$.configureSysProps$extension(FlywayPlugin.scala:295)
[error]         at io.github.davidmweber.FlywayPlugin$FlywayOps$.configure$extension0(FlywayPlugin.scala:239)
[error]         at io.github.davidmweber.FlywayPlugin$Flyway$.apply(FlywayPlugin.scala:219)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$48(FlywayPlugin.scala:181)
[error]         at io.github.davidmweber.FlywayPlugin$.withContextClassLoader(FlywayPlugin.scala:210)
[error]         at io.github.davidmweber.FlywayPlugin$.withPrepared(FlywayPlugin.scala:193)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$47(FlywayPlugin.scala:180)
[error]         at io.github.davidmweber.FlywayPlugin$.$anonfun$flywayBaseSettings$47$adapted(FlywayPlugin.scala:180)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:39)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:66)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:262)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:271)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:262)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:174)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:36)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (app / Prod / flywayInfo) org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: org.postgresql.Driver => Check whether the jar file is present

Might be related to flyway/flyway#1923

@binshi binshi changed the title Custom Congiguration failing for Postgresql Custom Configuration failing for Postgresql Feb 22, 2018
@davidmweber davidmweber added the bug label Apr 1, 2018
@davidmweber
Copy link
Collaborator

Looks like the postgresql jdbc jar is not on whatever classpath is presented in the custom configuration. Anybody know how this works in SBT?

@etspaceman
Copy link
Contributor

I'm using custom settings w/ the Postgres driver. In my experience, you have to add the Postgres JDBC jar as a library dependency in your build.sbt, like so:

"org.postgresql" % "postgresql" % "9.4-1206-jdbc41"

@muuki88
Copy link

muuki88 commented Jul 19, 2019

For custom configurations you'll need to configure the fullClasspath as well.

CustomConfig / fullClasspath := (Compile / fullClasspath).value,

The flyway is able to locate the proper jars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants