You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Scala 3执行Test/compile找不到lib/jar,但Scala 2.13正常

Scala 3.3下Molecule生成Jar包的编译问题排查请求

我使用sbt-molecule插件将生成的源码打包为Jar包,这些Jar包状态正常且已加入类路径。我有两个完全一致的最小测试项目,分别基于Scala 2.13和Scala 3.3版本:

  • Scala 2.13环境下执行sbt clean Test/compile可正常完成编译
  • Scala 3.3环境下执行相同命令会报错,错误信息如下:
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

我执行clean操作是为了确保测试代码仅依赖生成Jar包中的代码,这个逻辑在Scala 2.13下完全可行。

我曾怀疑是二进制兼容性问题,先后尝试切换JDK 8、11、20版本,但均未改善问题。

可通过以下命令复现问题(最后一条命令会执行失败):

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

注:-Dmolecule=true参数用于触发插件生成Jar包

Scala 3.3版本的项目构建配置如下:

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

希望能得到针对该问题的排查思路!

内容的提问来源于stack exchange,提问作者Marc Grue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 10:45:00