Sbt 无法在 Scala 3.0.0-M2 上找到列表 class 定义
Sbt unable to find List class definition on Scala 3.0.0-M2
我在 SDK 16 上有一个 scala 项目,在 Intellij 上使用 sbt IDEA Ultimate。这是我的 build.sbt
文件:
name := "meteo-france-client"
version := "0.1"
scalaVersion := "3.0.0-M2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.3.0-SNAP3" % Test
我有一个测试文件 src/scala/test/MainTest.scala
,代码如下:
import org.scalatest.funsuite.AnyFunSuite
class MainTest extends AnyFunSuite {
test("Example") {
assert(1 == 1)
}
}
请注意,在IDE中,import语句的“scalatest”和“test”函数名显示为红色并提示未找到,即使我可以编译该项目。
虽然我可以编译,但我不能 运行 测试。实际上,当我 运行 sbt test
它给了我以下错误:
[info] compiling 1 Scala source to C:\Users\adrie\OneDrive\Documents\dev\meteo-france-client\target\scala-3.0.0-M2\test-classes ...
[error] ## Exception when compiling 1 sources to C:\Users\adrie\OneDrive\Documents\dev\meteo-france-client\target\scala-3.0.0-M2\test-classes
[error] java.lang.NoClassDefFoundError: scala/collection/immutable/List
[error] xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:65)
[error] xsbt.CompilerInterface.run(CompilerInterface.java:41)
[error] java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
[error] java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] java.base/java.lang.reflect.Method.invoke(Method.java:567)
[error] sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:329)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:112)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile(MixedAnalyzingCompiler.scala:192)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile(MixedAnalyzingCompiler.scala:182)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$adapted(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.Incremental$.$anonfun$apply(Incremental.scala:175)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$adapted(Incremental.scala:173)
[error] sbt.internal.inc.Incremental$$anon.run(Incremental.scala:459)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile(Incremental.scala:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:501)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:167)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally(IncrementalCompilerImpl.scala:482)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2357)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask(Defaults.scala:2314)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask(Defaults.scala:2310)
[error] scala.Function1.$anonfun$compose(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon.$anonfun$submitValid(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon.call(CompletionService.scala:64)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
[error] java.base/java.lang.Thread.run(Thread.java:831)
[error]
[error] stack trace is suppressed; run 'last Test / compileIncremental' for the full output
[error] (Test / compileIncremental) java.lang.NoClassDefFoundError: scala/collection/immutable/List
[error] Total time: 0 s, completed 26 nov. 2021, 13:33:34
有人知道我为什么会收到此错误吗?
我可能错了,但看起来 Scala 3.0.0-M2 摆脱了 scala.collection.immutable.List
class.
感谢@stefanobaghino,事实证明我只需要更改我的 build.sbt 文件:
name := "meteo-france-client"
version := "0.1"
scalaVersion := "3.0.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % Test
因此从 Scala 3.0.0-M2 切换到 Scala 3.0.2,从 Sclatest 3.3.0-SNAP3 切换到 Scalatest 3.2.10。
我在 SDK 16 上有一个 scala 项目,在 Intellij 上使用 sbt IDEA Ultimate。这是我的 build.sbt
文件:
name := "meteo-france-client"
version := "0.1"
scalaVersion := "3.0.0-M2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.3.0-SNAP3" % Test
我有一个测试文件 src/scala/test/MainTest.scala
,代码如下:
import org.scalatest.funsuite.AnyFunSuite
class MainTest extends AnyFunSuite {
test("Example") {
assert(1 == 1)
}
}
请注意,在IDE中,import语句的“scalatest”和“test”函数名显示为红色并提示未找到,即使我可以编译该项目。
虽然我可以编译,但我不能 运行 测试。实际上,当我 运行 sbt test
它给了我以下错误:
[info] compiling 1 Scala source to C:\Users\adrie\OneDrive\Documents\dev\meteo-france-client\target\scala-3.0.0-M2\test-classes ...
[error] ## Exception when compiling 1 sources to C:\Users\adrie\OneDrive\Documents\dev\meteo-france-client\target\scala-3.0.0-M2\test-classes
[error] java.lang.NoClassDefFoundError: scala/collection/immutable/List
[error] xsbt.CachedCompilerImpl.run(CachedCompilerImpl.java:65)
[error] xsbt.CompilerInterface.run(CompilerInterface.java:41)
[error] java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
[error] java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] java.base/java.lang.reflect.Method.invoke(Method.java:567)
[error] sbt.internal.inc.AnalyzingCompiler.invoke(AnalyzingCompiler.scala:329)
[error] sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:112)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile(MixedAnalyzingCompiler.scala:192)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:247)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile(MixedAnalyzingCompiler.scala:182)
[error] sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$adapted(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compileScala(MixedAnalyzingCompiler.scala:163)
[error] sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:210)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$adapted(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.Incremental$.$anonfun$apply(Incremental.scala:175)
[error] sbt.internal.inc.Incremental$.$anonfun$apply$adapted(Incremental.scala:173)
[error] sbt.internal.inc.Incremental$$anon.run(Incremental.scala:459)
[error] sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
[error] sbt.internal.inc.IncrementalCommon$$anon.next(IncrementalCommon.scala:56)
[error] sbt.internal.inc.IncrementalCommon$$anon.next(IncrementalCommon.scala:52)
[error] sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
[error] sbt.internal.inc.Incremental$.$anonfun$incrementalCompile(Incremental.scala:414)
[error] sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:501)
[error] sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:401)
[error] sbt.internal.inc.Incremental$.apply(Incremental.scala:167)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:528)
[error] sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally(IncrementalCompilerImpl.scala:482)
[error] sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
[error] sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:420)
[error] sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
[error] sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:2357)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask(Defaults.scala:2314)
[error] sbt.internal.io.Retry$.apply(Retry.scala:46)
[error] sbt.internal.io.Retry$.apply(Retry.scala:28)
[error] sbt.internal.io.Retry$.apply(Retry.scala:23)
[error] sbt.internal.server.BspCompileTask$.compute(BspCompileTask.scala:31)
[error] sbt.Defaults$.$anonfun$compileIncrementalTask(Defaults.scala:2310)
[error] scala.Function1.$anonfun$compose(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon.$anonfun$submitValid(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon.call(CompletionService.scala:64)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
[error] java.base/java.lang.Thread.run(Thread.java:831)
[error]
[error] stack trace is suppressed; run 'last Test / compileIncremental' for the full output
[error] (Test / compileIncremental) java.lang.NoClassDefFoundError: scala/collection/immutable/List
[error] Total time: 0 s, completed 26 nov. 2021, 13:33:34
有人知道我为什么会收到此错误吗?
我可能错了,但看起来 Scala 3.0.0-M2 摆脱了 scala.collection.immutable.List
class.
感谢@stefanobaghino,事实证明我只需要更改我的 build.sbt 文件:
name := "meteo-france-client"
version := "0.1"
scalaVersion := "3.0.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % Test
因此从 Scala 3.0.0-M2 切换到 Scala 3.0.2,从 Sclatest 3.3.0-SNAP3 切换到 Scalatest 3.2.10。