samidarko
samidarko

Reputation: 632

slick codegen with custom profile

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.

Upvotes: 0

Views: 316

Answers (2)

sttawm
sttawm

Reputation: 77

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

Upvotes: 0

giorgio
giorgio

Reputation: 432

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

Upvotes: 0

Related Questions