slick-codegen-customization-example | code example shows how to setup sbt | Generator Utils library
kandi X-RAY | slick-codegen-customization-example Summary
kandi X-RAY | slick-codegen-customization-example Summary
This code example shows how to setup sbt to use a customized Slick code-generator for working with an existing database schema. project/Build.scala enables automatically as well as manually triggered code-generation. codegen/CustomizedCodeGenerator.scala contains the code customizing Slick's code-generator. codegen/Config.scala contains some shared configuration code between the code-generator and the main project. src/main/scala/Example.scala uses the generated code. The code is generated into file target/scala-2.11/src_managed/slick/demo/Tables.scala. The location can be changed in the sbt script. It is usally wise to keep the generated Slick code under version control.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of slick-codegen-customization-example
slick-codegen-customization-example Key Features
slick-codegen-customization-example Examples and Code Snippets
Community Discussions
Trending Discussions on slick-codegen-customization-example
QUESTION
I'm trying to run the Slick code generation with a customized generator (my ExampleCodeGenerator
). I place the ExampleCodeGenerator.scala
into the project
subdirectory, so that it's available to the build scripts. I construct a classpath: Seq[File]
that contains the classes
directory into which ExampleCodeGenerator
is compiled, plus the JARs from Compile / dependencyClasspath
.
If I follow the lead given in the Slick documentation for sbt and write in my .sbt
file:
ANSWER
Answered 2021-Sep-24 at 08:14I think I have this figured out.
The problem in the first case is that, in order to have my ExampleCodeGenerator
available in the main build scripts, I place it in the project
subdirectory. These files, though, are compiled with a version of the Scala compiler that sbt uses—in this case 2.12.14. In 2.12, scala.Serializable
is present, but in 2.13 it was replaced with a type alias. So this, in general, won't work, because I'm run
-ing the code with the Scala version of the base project, which can be different, and is in fact 2.13. I'm able to force this 2.12 classes
directory into the classpath, but to no avail.
In the second case, my guess is that the Class.forName()
being called from SourceCodeGenerator.main
is using the class loader of the SourceCodeGenerator
object's class, and that loader is an instance of sbt.internal.PluginManagement.PluginClassLoader
, a java.net.URLClassLoader
subclass that contains all the URLs of the JARs in the (base or build, not sure) project, but not the build project's classes
directory URL. So that loader can't find ExampleCodeGenerator
.
The solution seems to be what I have usually seen: create another subproject that builds a JAR that the base project depends on. This seems unavoidable.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install slick-codegen-customization-example
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page