2

I'm packaging jars from generated source code with an sbt-plugin and the jars are fine and on the classpath.

Now I have two identical minimal projects targeting Scala 2.13 and 3.3. With 2.13 I can run sbt clean Test/compile but with 3.3 it gives me this error:

Could not find null in Some(.../test-project-3/lib/molecule-test-project-3.jar)
-- [E006] Not Found Error: .../test-project-3/src/test/scala/app/Connection.scala:14:23 
14 |  val schema: Schema = PersonSchema
   |                       ^^^^^^^^^^^^
   |                       Not found: PersonSchema

I clean to make sure that the test code picks up the code in the generated jars only (which works fine with 2.13).

I thought then that it might have to do with som binary issues and therefore tried running with JDK versions 8, 11 and 20, but that didn't make a difference.

The following commands compiles the two projects (and the last one fails):

git clone https://github.com/scalamolecule/sbt-molecule.git
cd sbt-molecule/test-project-2
sbt clean compile -Dmolecule=true
sbt clean Test/compile
cd ../test-project-3
sbt clean compile -Dmolecule=true
sbt clean Test/compile

(the -Dmolecule=true flag makes the plugin generate jars)

Thankful for any ideas of what this might be about!

Build file for 3.3 version:

name := "sbt-molecule-test-project"
version := "1.8.1-SNAPSHOT"
organization := "org.scalamolecule"
scalaVersion := "3.3.3"
libraryDependencies ++= Seq(
  "com.lihaoyi" %% "utest" % "0.8.3",
  "org.scalamolecule" %% "molecule-sql-h2" % "0.9.0",
)
testFrameworks += new TestFramework("utest.runner.Framework")
Test / parallelExecution := false

// Molecule
enablePlugins(MoleculePlugin)

// Generate Molecule boilerplate code with `sbt clean compile -Dmolecule=true`
moleculePluginActive := sys.props.get("molecule").contains("true")

// tells plugin where to look for definitions of code to be generated
moleculeDataModelPaths := Seq("app") 

// Doesn't make a difference
//Test / fork := true
4
  • 1
    Could you share relevant part of the build.sbt file?
    – Gaël J
    Commented Jul 6 at 16:37
  • Sure - not much to show though..
    – Marc Grue
    Commented Jul 6 at 16:49
  • Is Connection.scala a generated file? Where is PersonSchema supposed to be defined? Did you open the JAR file to see what's in it?
    – Gaël J
    Commented Jul 7 at 6:48
  • Connection is a test file and PersonSchema is generated and is present in the jar. So the jar and the generation process itself seems fine. The problem arise when the generated source files are cleaned away and sbt compiles the test code, then it doesn't find (or can't use) the jar.
    – Marc Grue
    Commented Jul 7 at 9:49

1 Answer 1

1

Generated jar for class files missed Scala 3's new .tasty files.

I had filtered class files to be included in the jar by the file name extension ".class" and had missed to now also include ".tasty" for Scala 3. Once added, everything works like a charm.

So I missed that the jars were actually not fine.

Not the answer you're looking for? Browse other questions tagged or ask your own question.