scalasbtscala-3

Test/compile not finding lib/jar with Scala 3 (but 2.13 works)


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

Solution

  • 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.