0

I'm trying to use a custom profile in my sbt slickCodeGen task but I keep hitting a ClassNotFoundException.

The sbt task look like this:

lazy val slickCodeGen = taskKey[Unit]("Slick: generate Table")

slickCodeGen := {    
    val dir = (sourceDirectory in Compile).value    
    val cp = (dependencyClasspath in Compile).value
    val s = streams.value   
    val outputDir = (dir / "scala").getPath    
    val username = "dev"
    val password = ""    
    val url = "jdbc:postgresql://localhost/db"   
    val jdbcDriver = "org.postgresql.Driver" 
    val profile = "org.samidarko.models.PostgresProfile" 
    val pkg = "org.samidarko.models" 
    val r = (runner in Compile).value   
    r.run("slick.codegen.SourceCodeGenerator", cp.files, Array(profile, jdbcDriver, url, outputDir, pkg, username, password), s.log)  
}

My custom profile is org.samidarko.models.PostgresProfile and looks like pretty much like this

Basically, every times I run the command sbt slickCodeGen I receive

[error] (run-main-0) java.lang.ClassNotFoundException: org.samidarko.models.PostgresProfile$

[error] java.lang.ClassNotFoundException: org.samidarko.models.PostgresProfile$

...

I went through the sbt documentation but I couldn't figure how to add the classpath to my sources for this task. Any help would be appreciated.

Community
  • 1
  • 1
samidarko
  • 590
  • 7
  • 20

2 Answers2

0

Instead of dependencyClasspath in Compile use fullClasspath in Compile see https://www.scala-sbt.org/1.x/docs/Howto-Classpaths.html

giorgio
  • 392
  • 3
  • 10
  • Is that Q/A pair basically the same as this one here? Then please flag as duplicate instead of linking. If it is different and only one of the answers happens to be helpful here, then please explain the difference of the questions and why the answer still helps. – Yunnosch Sep 08 '20 at 12:47
  • @Yunnosch Unfortunately no accepted answer on that question it doesn't allow me to flag it as duplicate. I've duplicated my answer (a better one) – giorgio Sep 08 '20 at 13:58
  • You are right Sorry, I did not notice this obstacle. I am unsure how to handle this. I think having the basically same answer here and there is acceptable in this case. Would you like to mention (in a comment or in the answer) the link to the other one? Maybe also there link here. I imagine that as soon as one of the answers gets accepted or upvoted turning the other one into an official duplicate is then easier. – Yunnosch Sep 08 '20 at 14:17
  • Sorry for late reply but I deprecated this application due to too many pain points using scala + sbt. Migrated to Elixir that fulfilled its promises. FYI, replacing `dependencyClasspath` by `fullClasspath` raises an exception. https://pastebin.com/JSZ7T2zy – samidarko Oct 05 '20 at 15:27
  • @samidarko It looks the exception is just reminding you to load the env variables. If you have a .env file in your root just add the plugin `addSbtPlugin("au.com.onegeek" %% "sbt-dotenv" % "2.1.146")` – giorgio Oct 08 '20 at 08:34
0

Try adding project/PostgresProfile.scala that looks like:

package org.samidarko.models.PostgresProfile

// HACK to make sbt think this class is available when referenced in build.sbt
object PostgresProfile extends slick.jdbc.PostgresProfile
sttawm
  • 47
  • 7