tototoshi / sbt-slick-codegen

slick-codegen compile hook for sbt
69 stars 19 forks source link

Can't find postgres driver #20

Open mrwillis opened 6 years ago

mrwillis commented 6 years ago

Hi,

I have a very simple setup trying to use this plugin. Here is part of my build.sbt file:

sourceGenerators in Compile <+= slickCodegen
slickCodegenDatabaseUrl := "..."
slickCodegenDatabaseUser := "..."
slickCodegenDatabasePassword := "..."

and above I have

libraryDependencies += "org.postgresql"      % "postgresql"            % "42.2.2"

and in my plugins.sbt I have

addSbtPlugin("com.github.tototoshi" % "sbt-slick-codegen" % "1.3.0")

but for some reason, when I run slickCodegen, I'm getting that it can't find org.postgresql.Driver. This is very odd. If I try to do import org.postgresql.Driver at the top of build.sbt, it doesn't seem to be able to find it. However, I am using this driver in the rest of my app with play-slick, so I'm not sure what it going on.

$ slickCodegen
[error] java.lang.RuntimeException: Failed to run slick-codegen: org.postgresql.Driver
[error]     at com.github.tototoshi.sbt.slick.CodegenPlugin$.gen(CodegenPlugin.scala:84)
[error]     at com.github.tototoshi.sbt.slick.CodegenPlugin$.$anonfun$projectSettings$13(CodegenPlugin.scala:156)
[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.lang.ClassLoader.findClass(ClassLoader.java:530)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error]     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error]     at slick.util.ClassLoaderUtil$$anon$1.loadClass(ClassLoaderUtil.scala:17)
[error]     at slick.jdbc.DriverDataSource.$anonfun$init$2(DriverDataSource.scala:61)
[error]     at scala.Option.getOrElse(Option.scala:121)
[error]     at slick.jdbc.DriverDataSource.liftedTree1$1(DriverDataSource.scala:59)
[error]     at slick.jdbc.DriverDataSource.init(DriverDataSource.scala:55)
[error]     at slick.jdbc.DriverDataSource.getConnection(DriverDataSource.scala:100)
[error]     at slick.jdbc.DataSourceJdbcDataSource.createConnection(JdbcDataSource.scala:71)
[error]     at com.github.tototoshi.sbt.slick.CodegenPlugin$.gen(CodegenPlugin.scala:81)
[error]     at com.github.tototoshi.sbt.slick.CodegenPlugin$.$anonfun$projectSettings$13(CodegenPlugin.scala:156)
[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] (slickCodegen) Failed to run slick-codegen: org.postgresql.Driver
[error] Total time: 1 s, completed 24-Apr-2018 5:11:23 PM

Any guidance would be appreciated.

Thanks

MazenAtaya commented 6 years ago

I'm having the same issue

nafg commented 6 years ago

The plugin runs as part of the build, not your application. libraryDependencies in your top build.sbt adds it to your application. You probably need to add the libraryDependencies in plugins.sbt.

extirpate commented 5 months ago

The plugin runs as part of the build, not your application. libraryDependencies in your top build.sbt adds it to your application. You probably need to add the libraryDependencies in plugins.sbt.

thank you very much , i am a new scala learner, this problem cost me 60 hours, and you solved my problem . can you tell me how do you know this, so greate. if i did't see your post, i will never solve this problem , so terrible!

nafg commented 5 months ago

@extirpate read https://www.scala-sbt.org/1.x/docs/Organizing-Build.html, and google for other SBT resources