Ammonite
Ammonite copied to clipboard
Issues using Ammonite 2.5 in SBT Project
Hi, I'm having some issues trying to use Ammonite 2.5 in my project.
My SBT file can be viewed at https://github.com/OOPMan/collectioneer/blob/master/build.sbt
When I attempt to sbt update I get the following:
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/E:/Development/Scala/collectioneer/"), "collectioneer"):
[error] com.lihaoyi:sourcecode _3, _2.13
[error] com.lihaoyi:fansi _3, _2.13
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/E:/Development/Scala/collectioneer/"), "core"):
[error] org.scala-lang.modules:scala-collection-compat _3, _2.13
[error] com.lihaoyi:sourcecode _3, _2.13
[error] com.lihaoyi:fansi _3, _2.13
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/E:/Development/Scala/collectioneer/"), "repl"):
[error] com.lihaoyi:sourcecode _3, _2.13
[error] com.lihaoyi:fansi _3, _2.13
[error] stack trace is suppressed; run 'last core / update' for the full output
[error] stack trace is suppressed; run 'last repl / update' for the full output
[error] stack trace is suppressed; run 'last update' for the full output
[error] (core / update) Conflicting cross-version suffixes in: org.scala-lang.modules:scala-collection-compat, com.lihaoyi:sourcecode, com.lihaoyi:fansi
[error] (repl / update) Conflicting cross-version suffixes in: com.lihaoyi:sourcecode, com.lihaoyi:fansi
[error] (update) Conflicting cross-version suffixes in: com.lihaoyi:sourcecode, com.lihaoyi:fansi
[error] Total time: 0 s, completed Dec 22, 2021, 10:31:51 AM
[IJ]```
I'm not quite sure what's happening here. Can anyone assist?
I have the same issue (same exception) - I could not figure out how to use Ammonite in a Scala 3 project.
The sbt dependencyTree shows this:

Strange that com.lihaoyi:ammonite-cross-3.1.1-util_2.13 depends on both.
@pme123 The frustrating thing is that I was using an earlier version with no issues.
tl;dr; I tried to work around the duplicate dependencies but haven't found a way forward yet.
Full version: I tried to exclude the _2.13 sibling of the duplicated dependencies:
excludeDependencies ++= Seq(
"fansi",
"os-lib",
"geny",
"upack",
"ujson",
"upickle",
"upickle-core",
"upickle-implicits",
"sourcecode",
"pprint"
).map(artifactName =>
ExclusionRule("com.lihaoyi", s"${artifactName}_2.13")
) :+ ExclusionRule("org.scala-lang.modules", "scala-xml_2.13")
Some ammonite artifacts don't exist for scala 3 yet, e.g. ammonite-storage and ammonite-util. I guess because they rely on things like TypeTag which got dropped in Scala3.
Apart from that scalac is happy. However, at runtime there's a variety of linker issues, e.g.
scala> ammonite.runtime.Storage.toString
java.lang.NoSuchMethodError: 'void upickle.core.Types$Writer.$init$(upickle.core.Types$Writer)'
at ammonite.runtime.Storage$$anon$27.<init>(Storage.scala:110)
at ammonite.runtime.Storage$.<clinit>(Storage.scala:110)
... 66 elided
I also tried to selectively pick and mix _2.13 and _3 from the exclusionlist above, but just ended up with different compiler and/or linker issues.
fwiw a workaround is to turn it around: rather than adding ammonite as a dependency to your build, you can start the regular amm repl and load up all your project's jars.
fwiw tried something else, still no success though:
Selectively add dependencies in util: only add fansi for scala2 and only add fansi_3 for scala3: https://github.com/mpollmeier/Ammonite/commit/97b59317beca3af514d3e477b5aedb859ede5734
mill "amm[3.2.0].compile"
...
[error] amm/repl/src/main/scala/ammonite/repl/AmmoniteFrontEnd.scala:50:9: Unsupported Scala 3 inline macro method generate; found in trait sourcecode.EnclosingMacros.
[error] val autocompleteFilter: Filter = Filter.action(SpecialKeys.Tab){
[error] ^
[error] amm/repl/src/main/scala/ammonite/repl/AmmoniteFrontEnd.scala:104:6: could not find implicit value for parameter i: sourcecode.Enclosing
[error] ){
[error] ^
[error] amm/repl/src/main/scala/ammonite/repl/AmmoniteFrontEnd.scala:113:34: could not find implicit value for parameter i: sourcecode.Enclosing
[error] val allFilters = Filter.merge(
[error] ^
[error] three errors found
1 targets failed
amm.repl[3.2.0].compile Compilation failed