Scala:java.lang.NoClassDefFoundError:无法初始化类 sbt.internal.parser.SbtParser

问题描述 投票:0回答:1

我无法在现有 Scala 项目上使用 sbt 或在 IntelliJ 中运行测试。我的设置看起来很基本。

% brew install coursier/formulas/coursier && cs setup
% cs setup
Checking if a JVM is installed
Found a JVM installed under /opt/homebrew/Cellar/openjdk/21/libexec/openjdk.jdk/Contents/Home.

Checking if ~/Library/Application Support/Coursier/bin is in PATH

Checking if the standard Scala applications are installed
  Found ammonite
  Found cs
  Found coursier
  Found scala
  Found scalac
  Found scala-cli
  Found sbt
  Found sbtn
  Found scalafmt

% scala -version
Scala code runner version 3.3.1 -- Copyright 2002-2023, LAMP/EPFL

% java -version
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment Homebrew (build 21)
OpenJDK 64-Bit Server VM Homebrew (build 21, mixed mode, sharing)

build.sbt 中发生了很多事情,所以这里有一些亮点:

enablePlugins(JavaAppPackaging, ScoverageSbtPlugin)

lazy val root = (project in file(".")).settings(
  inThisBuild(
    List(
      scalaVersion := "2.13.10"
    )
  ),
  ...

scalacOptions ++= Seq(
  "-feature",
  "-language:postfixOps",
  "-language:implicitConversions",
  "-release:17",
  "-unchecked",
  "-Wconf:cat=other-match-analysis:error"
)

javacOptions ++= Seq("-source", "17", "-target", "17")

仅运行

sbt
会导致一系列冗长且有些难以理解的编译器错误。

% sbt
error:
  bad constant pool index: 0 at pos: 48445
     while compiling: <no file>
        during phase: globalPhase=<no phase>, enteringPhase=<some phase>
     library version: version 2.12.16
    compiler version: version 2.12.16
  reconstructed args: -classpath /Users/macdoogie/.sbt/boot/scala-2.12.16/lib/scala-library.jar -Yrangepos

  last tree to typer: EmptyTree
       tree position: <unknown>
            tree tpe: <notype>
              symbol: null
           call site: <none> in <none>

这会产生更多的输出,但这看起来很有趣: [错误] java.lang.NoClassDefFoundError:无法初始化类 sbt.internal.parser.SbtParser

我也尝试从 intellij 运行东西,但我一直收到此错误:

scalac: Error while emitting dev/macdoogie/StartApp$
Unsupported class file major version 64

我也尝试过

% rm -rf ~/.sbt
% rm -rf ~/.ivy2
% rm -rf ~/.ivy
scala sbt
1个回答
0
投票

检查项目中

sbt.version
处的
project/build.properties
。也许你可以通过将sbt版本更改为最新来解决它。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.