Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

troubleshooting jar loading conflicts in sbt

I get the following error on sbt startup, when two specific sbt plugins are added together to a project in its build definition. One of these sbt plugins is scalikejdbc and the other is my own, and clearly their mutual inclusion in a project's build definition results in this error upon sbt startup:

scala.reflect.internal.Types$TypeError: package macros contains object
and package with same name: blackbox

Clearly, it looks as if each plugin brings along a different version of scala.reflect.macros thus causing this error. I can poke inside the jars of the sbt plugins, and indeed one of them may seem to bring along a scala/reflect/macros/blackbox.class

$ jar -tvf scalikejdbc-core_2.10/jars/scalikejdbc-core_2.10-2.4.2.jar | grep black

  0 Sat Jun 11 15:51:10 IDT 2016 scala/reflect/macros/blackbox/    
405 Sat Jun 11 15:51:04 IDT 2016 scala/reflect/macros/blackbox/package$.class    
419 Sat Jun 11 15:51:04 IDT 2016 scala/reflect/macros/blackbox/package.class

― however it's hard to positively conclude what gets loaded by sbt during this early startup phase, in order to figure which versions of this package are involved here and which dependencies bring them along.

Thanks for your suggestions about how to proceed with this investigation!


And just for completeness sake ― I include below the full error given by sbt below only ― but I sincerely doubt it adds any information so you can likely ignore it.

scala.reflect.internal.Types$TypeError: package macros contains object and package with same name: blackbox
one of them needs to be removed from classpath
    at scala.tools.nsc.symtab.SymbolLoaders.enterPackage(SymbolLoaders.scala:66)
    at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$4.apply(SymbolLoaders.scala:244)
    at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$4.apply(SymbolLoaders.scala:243)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:243)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:194)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)
    at scala.reflect.internal.pickling.UnPickler$Scan.scala$reflect$internal$pickling$UnPickler$Scan$$fromName$1(UnPickler.scala:207)
    at scala.reflect.internal.pickling.UnPickler$Scan.readExtSymbol$1(UnPickler.scala:226)
    at scala.reflect.internal.pickling.UnPickler$Scan.readSymbol(UnPickler.scala:250)
    at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolRef(UnPickler.scala:783)
    at scala.reflect.internal.pickling.UnPickler$Scan.readType(UnPickler.scala:335)
    at scala.reflect.internal.pickling.UnPickler$Scan$$anonfun$readTypeRef$1.apply(UnPickler.scala:792)
    at scala.reflect.internal.pickling.UnPickler$Scan$$anonfun$readTypeRef$1.apply(UnPickler.scala:792)
    at scala.reflect.internal.pickling.UnPickler$Scan.at(UnPickler.scala:171)
    at scala.reflect.internal.pickling.UnPickler$Scan.readTypeRef(UnPickler.scala:792)
    at scala.reflect.internal.pickling.UnPickler$Scan.readType(UnPickler.scala:345)
    at scala.reflect.internal.pickling.UnPickler$Scan$$anonfun$readTypeRef$1.apply(UnPickler.scala:792)
    at scala.reflect.internal.pickling.UnPickler$Scan$$anonfun$readTypeRef$1.apply(UnPickler.scala:792)
    at scala.reflect.internal.pickling.UnPickler$Scan.at(UnPickler.scala:171)
    at scala.reflect.internal.pickling.UnPickler$Scan.readTypeRef(UnPickler.scala:792)
    at scala.reflect.internal.pickling.UnPickler$Scan.readAnnotationInfo(UnPickler.scala:466)
    at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolAnnotation(UnPickler.scala:491)
    at scala.reflect.internal.pickling.UnPickler$Scan.run(UnPickler.scala:88)
    at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:37)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$parseAttribute$1(ClassfileParser.scala:908)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.parseAttributes(ClassfileParser.scala:1084)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:580)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:88)
    at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:261)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:194)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)
    at scala.reflect.internal.SymbolTable.openPackageModule(SymbolTable.scala:244)
    at scala.reflect.internal.SymbolTable.openPackageModule(SymbolTable.scala:300)
    at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader.doComplete(SymbolLoaders.scala:247)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:194)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.load(SymbolLoaders.scala:210)
    at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1489)
    at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$isRawIfWithoutArgs(Types.scala:4394)
    at scala.reflect.internal.Types$$anon$11.apply(Types.scala:4416)
    at scala.reflect.internal.Symbols$TermSymbol.scala$reflect$internal$Symbols$TermSymbol$$cook$1(Symbols.scala:2581)
    at scala.reflect.internal.Symbols$TermSymbol.doCookJavaRawInfo(Symbols.scala:2589)
    at scala.reflect.internal.Symbols$Symbol.cookJavaRawInfo(Symbols.scala:1442)
    at scala.tools.nsc.typechecker.Infer$Inferencer.checkAccessible(Infer.scala:384)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$makeAccessible(Typers.scala:605)
    at scala.tools.nsc.typechecker.Typers$Typer.typedIdent$2(Typers.scala:5201)
    at scala.tools.nsc.typechecker.Typers$Typer.typedIdentOrWildcard$1(Typers.scala:5218)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5561)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5727)
    at scala.tools.nsc.typechecker.Typers$Typer.typedQualifier(Typers.scala:5735)
    at scala.tools.nsc.typechecker.Namers$Namer.importSig(Namers.scala:1357)
    at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1460)
    at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1463)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:728)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:727)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:727)
    at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$logAndValidate(Namers.scala:1496)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:727)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:726)
    at scala.tools.nsc.typechecker.Namers$$anon$1.completeImpl(Namers.scala:1611)
    at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter$class.complete(Namers.scala:1619)
    at scala.tools.nsc.typechecker.Namers$$anon$1.complete(Namers.scala:1609)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1231)
    at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1374)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2912)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3032)
    at scala.collection.immutable.List.loop$1(List.scala:170)
    at scala.collection.immutable.List.mapConserve(List.scala:186)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3032)
    at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:5301)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5587)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5642)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5704)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:464)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:91)
    at sbt.compiler.Eval$$anonfun$compile$1$1.apply$mcV$sp(Eval.scala:177)
    at sbt.compiler.Eval$$anonfun$compile$1$1.apply(Eval.scala:177)
    at sbt.compiler.Eval$$anonfun$compile$1$1.apply(Eval.scala:177)
    at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:207)
    at sbt.compiler.Eval.compile$1(Eval.scala:177)
    at sbt.compiler.Eval.compileAndLoad(Eval.scala:182)
    at sbt.compiler.Eval.evalCommon(Eval.scala:152)
    at sbt.compiler.Eval.evalDefinitions(Eval.scala:122)
    at sbt.EvaluateConfigurations$.evaluateDefinitions(EvaluateConfigurations.scala:271)
    at sbt.EvaluateConfigurations$.evaluateSbtFile(EvaluateConfigurations.scala:109)
    at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:725)
    at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:731)
    at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:730)
    at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
    at scala.collection.AbstractMap.getOrElse(Map.scala:58)
    at sbt.Load$.sbt$Load$$memoLoadSettingsFile$1(Load.scala:730)
    at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:738)
    at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:738)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at sbt.Load$.loadFiles$1(Load.scala:738)
    at sbt.Load$.discoverProjects(Load.scala:749)
    at sbt.Load$.discover$1(Load.scala:555)
    at sbt.Load$.loadTransitive(Load.scala:584)
    at sbt.Load$.loadProjects$1(Load.scala:452)
    at sbt.Load$.loadUnit(Load.scala:456)
    at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:291)
    at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:291)
    at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:91)
    at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:90)
    at sbt.BuildLoader.apply(BuildLoader.scala:140)
    at sbt.Load$.loadAll(Load.scala:344)
    at sbt.Load$.loadURI(Load.scala:299)
    at sbt.Load$.load(Load.scala:295)
    at sbt.Load$.load(Load.scala:286)
    at sbt.Load$.apply(Load.scala:140)
    at sbt.Load$.defaultLoad(Load.scala:36)
    at sbt.BuiltinCommands$.liftedTree1$1(Main.scala:492)
    at sbt.BuiltinCommands$.doLoadProject(Main.scala:492)
    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484)
    at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:484)
    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
    at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:59)
    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
    at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
    at sbt.Command$.process(Command.scala:93)
    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
    at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
    at sbt.State$$anon$1.process(State.scala:184)
    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
    at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.MainLoop$.next(MainLoop.scala:96)
    at sbt.MainLoop$.run(MainLoop.scala:89)
    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
    at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
    at sbt.Using.apply(Using.scala:24)
    at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
    at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
    at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
    at sbt.MainLoop$.runLogged(MainLoop.scala:22)
    at sbt.StandardMain$.runManaged(Main.scala:54)
    at sbt.xMain.run(Main.scala:29)
    at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
    at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
    at xsbt.boot.Launch$.run(Launch.scala:109)
    at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
    at xsbt.boot.Launch$.launch(Launch.scala:117)
    at xsbt.boot.Launch$.apply(Launch.scala:18)
    at xsbt.boot.Boot$.runImpl(Boot.scala:41)
    at xsbt.boot.Boot$.main(Boot.scala:17)
    at xsbt.boot.Boot.main(Boot.scala)
error: error while loading package, class file '/home/user/.sbt/boot/scala-2.10.6/org.scala-sbt/sbt/0.13.11/sbt-0.13.11.jar(sbt/package.class)' is broken
(class java.lang.RuntimeException/error reading Scala signature of package.class: package macros contains object and package with same name: blackbox
one of them needs to be removed from classpath)
sbt.compiler.EvalException: Type error in expression
like image 862
matanster Avatar asked Aug 19 '16 19:08

matanster


People also ask

Can SBT run a JAR file created by SBT?

A JAR file created by SBT can be run by the Scala interpreter, but not the Java interpreter. This is because class files in the JAR file created by sbt package have dependencies on Scala class files (Scala libraries), which aren’t included in the JAR file SBT generates. This is easily demonstrated. First, create an empty SBT project directory.

What is a fat jar in SBT?

On the other hand, a fat JAR, also known as an uber JAR, is built with all of the project dependencies included. The advantage of using a fat JAR is that we can distribute it to any destination, regardless of whether the project dependencies are present in the running environment or not. 3. The sbt-assembly Plugin

How do I create a single executable JAR file using sbt-Assembly?

See the sbt-assembly project documentation for the latest version and configuration information. Now run sbt assembly to create your single, executable JAR file: When the assembly task finishes running it will tell you where the executable JAR file is located.

What is the SBT assembly plugin?

The sbt-assembly Plugin The sbt-assembly plugin is an SBT plugin for building a single independent fat JAR file with all dependencies included. This is inspired by the popular Maven assembly plugin, which is used to build fat JARs in Maven.


1 Answers

Copying @jrudolph's comment here:

FWIW giving some advice to someone coming to this issue later on also having problems with plugin classpaths. Try adding scalacOptions ++= Seq("-verbose", "-Ylog-classpath") to project/plugins.sbt. This will print out detailed information when the scala compiler loads classes when compiling the build. This should give a hint from which the jar the conflicting classes came from.

like image 165
Eugene Yokota Avatar answered Sep 21 '22 08:09

Eugene Yokota