it-swarm.com.de

Der Versuch, ein Projekt nach Scala 2.11 zu kompilieren, schlägt fehl mit "Fehler beim Laden von Object, fehlende Abhängigkeit 'object scala in compiler mirror'"

Ich versuche, mein Projekt auf Scala 2.10 und 2.11 zu kompilieren, damit ich Versionen für beide Scala-Versionen freigeben kann. Bei jedem Versuch schlägt dies jedoch mit der folgenden Meldung fehl:

#( 04/26/[email protected] 7:40 )( [email protected] ):~/projects/scala/[email protected]✔
   sbt compile
[info] Loading project definition from /Users/mauricio/projects/scala/postgresql-netty/project
[info] Set current project to db-async-base (in build file:/Users/mauricio/projects/scala/postgresql-netty/)
[info] Compiling 61 Scala sources and 1 Java source to /Users/mauricio/projects/scala/postgresql-netty/db-async-common/target/scala-2.11/classes...
[error] error while loading Object, Missing dependency 'object scala in compiler mirror', required by /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/rt.jar(Java/lang/Object.class)
scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
    at scala.reflect.internal.MissingRequirementError$.signal(MissingRequirementError.scala:17)
    at scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:18)
    at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:53)
    at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
    at scala.reflect.internal.Mirrors$RootsBase.getPackage(Mirrors.scala:173)
    at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage$lzycompute(Definitions.scala:161)
    at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackage(Definitions.scala:161)
    at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass$lzycompute(Definitions.scala:162)
    at scala.reflect.internal.Definitions$DefinitionsClass.ScalaPackageClass(Definitions.scala:162)
    at scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1375)
    at scala.tools.nsc.Global$Run.<init>(Global.scala:1278)
    at xsbt.CachedCompiler0$$anon$2.<init>(CompilerInterface.scala:113)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:113)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:99)
    at xsbt.CompilerInterface.run(CompilerInterface.scala:27)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:606)
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:102)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:48)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:99)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:99)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:99)
    at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:166)
    at sbt.compiler.AggressiveCompile$$anonfun$3.compileScala$1(AggressiveCompile.scala:98)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:143)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:87)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:39)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:37)
    at sbt.inc.IncrementalCommon.cycle(Incremental.scala:99)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:38)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:37)
    at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:65)
    at sbt.inc.Incremental$.compile(Incremental.scala:37)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:27)
    at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:157)
    at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:71)
    at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:46)
    at sbt.Compiler$.apply(Compiler.scala:75)
    at sbt.Compiler$.apply(Compiler.scala:66)
    at sbt.Defaults$.sbt$Defaults$$compileTaskImpl(Defaults.scala:743)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:735)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:735)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:42)
    at sbt.std.Transform$$anon$4.work(System.scala:64)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
    at sbt.Execute.work(Execute.scala:244)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:262)
    at Java.util.concurrent.Executors$RunnableAdapter.call(Executors.Java:471)
    at Java.util.concurrent.FutureTask.run(FutureTask.Java:262)
    at Java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.Java:1145)
    at Java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.Java:615)
    at Java.lang.Thread.run(Thread.Java:744)
[error] (db-async-common/compile:compile) scala.reflect.internal.MissingRequirementError: object scala in compiler mirror not found.
[error] Total time: 2 s, completed Apr 26, 2014 7:43:49 PM

Meine Build-Datei sieht folgendermaßen aus:

import sbt._
import Keys._

object ProjectBuild extends Build {

  val commonName = "db-async-common"
  val postgresqlName = "postgresql-async"
  val mysqlName = "mysql-async"

  lazy val root = Project(
    id = "db-async-base",
    base = file("."),
    settings = Configuration.baseSettings,
    aggregate = Seq(common, postgresql, mysql)
  )

  lazy val common = Project(
    id = commonName,
    base = file(commonName),
    settings = Configuration.baseSettings ++ Seq(
      name := commonName,
      libraryDependencies := Configuration.commonDependencies
    )
  )

  lazy val postgresql = Project(
    id = postgresqlName,
    base = file(postgresqlName),
    settings = Configuration.baseSettings ++ Seq(
      name := postgresqlName,
      libraryDependencies ++= Configuration.implementationDependencies
    )
  ) aggregate (common) dependsOn (common)

  lazy val mysql = Project(
    id = mysqlName,
    base = file(mysqlName),
    settings = Configuration.baseSettings ++ Seq(
      name := mysqlName,
      libraryDependencies ++= Configuration.implementationDependencies
    )
  ) aggregate (common) dependsOn (common)

}

object Configuration {

  val commonVersion = "0.2.13"
  val projectScalaVersion = "2.11.0"

  val specs2Dependency = "org.specs2" %% "specs2" % "2.3.11" % "test"
  val logbackDependency = "ch.qos.logback" % "logback-classic" % "1.0.13" % "test"

  val commonDependencies = Seq(
    "org.slf4j" % "slf4j-api" % "1.7.5",
    "joda-time" % "joda-time" % "2.3",
    "org.joda" % "joda-convert" % "1.5",
    "io.netty" % "netty-all" % "4.0.18.Final",
    "org.javassist" % "javassist" % "3.18.1-GA",
    specs2Dependency,
    logbackDependency
  )

  val implementationDependencies = Seq(
    specs2Dependency,
    logbackDependency
  )

  val baseSettings = Defaults.defaultSettings ++ Seq(
    scalacOptions :=
      Opts.compile.encoding("UTF8")
        :+ Opts.compile.deprecation
        :+ Opts.compile.unchecked
        :+ "-feature"
    ,
    scalacOptions in doc := Seq("-doc-external-doc:scala=http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/"),
    scalaVersion := projectScalaVersion,
    crossScalaVersions := Seq(projectScalaVersion, "2.10.4"),
    javacOptions := Seq("-source", "1.6", "-target", "1.6", "-encoding", "UTF8"),
    organization := "com.github.mauricio",
    version := commonVersion,
    parallelExecution := false,
    publishArtifact in Test := false,
    publishMavenStyle := true,
    pomIncludeRepository := {
      _ => false
    },
    publishTo <<= version {
      v: String =>
        val nexus = "https://oss.sonatype.org/"
        if (v.trim.endsWith("SNAPSHOT"))
          Some("snapshots" at nexus + "content/repositories/snapshots")
        else
          Some("releases" at nexus + "service/local/staging/deploy/maven2")
    },
    pomExtra := (
      <url>https://github.com/mauricio/postgresql-async</url>
        <licenses>
          <license>
            <name>Apache-2.0</name>
            <url>http://www.Apache.org/licenses/LICENSE-2.0</url>
            <distribution>repo</distribution>
          </license>
        </licenses>
        <scm>
          <url>[email protected]:mauricio/postgresql-netty.git</url>
          <connection>scm:git:[email protected]:mauricio/postgresql-netty.git</connection>
        </scm>
        <developers>
          <developer>
            <id>mauricio</id>
            <name>Maurício Linhares</name>
            <url>https://github.com/mauricio</url>
          </developer>
        </developers>
      )
  )

}

Und wenn Sie die Quelle ziehen möchten, um zu überprüfen, ob es sich um in diesem Zweig auf Github handelt.

Alle Informationen zum Versuch, dies zu beheben, wären sehr hilfreich.

15

Das Problem ist sehr einfach, in Ihrem Build.scala haben Sie fast alles richtig gemacht, aber in einem Commons-Projekt haben Sie den Standardwert commonDependencies überschrieben. Standardmäßig enthält es die Abhängigkeit zur Scala-Bibliothek.

Dieser Code

lazy val common = Project(
    id = commonName,
    base = file(commonName),
    settings = Configuration.baseSettings ++ Seq(
      name := commonName,
      libraryDependencies := Configuration.commonDependencies // #1
    )
  )

bei dem als #1 markierten Element sollte haben

libraryDependencies ++= Configuration.commonDependencies

Ps. Ich habe dir eine Pull-Anfrage mit dem Fix geschickt.

16
lpiepiora

Ich habe diese Fehlermeldung erhalten, als ich versucht habe, Oracle Java 9 jvm unter Ubuntu mit sbt zu verwenden. Die Verwendung von Java 8 JVM funktionierte jedoch für mich.

8
Jack Davidson

Ich denke, Sie haben vor Ihren Fragen geantwortet Multimodul-Projektaufbau mit SBT bricht mit seltsamem Fehler ab

In diesem Build fügen Sie eine Zeile hinzu "org.scala-lang" % "scala-library" % projectScalaVersion,:

 val commonDependencies = Seq(
    ..
    "org.joda" % "joda-convert" % "1.5",
    "org.scala-lang" % "scala-library" % projectScalaVersion,
    "io.netty" % "netty-all" % "4.0.18.Final",
    ...
  )
3
Andrzej Jozwik

In Build.scala würde ich autoScalaLibrary := true hinzufügen:

lazy val common = Project(
    id = commonName,
    base = file(commonName),
    settings = Configuration.baseSettings ++ Seq(
      ...
      autoScalaLibrary := true,
      ...
    )
  )
2
Filippo Vitale