0

I'm compiling a multi-part Scala project. It's not that large, but some of it is Scala 2.13 and some is Scala 3.

Attempting to compile generates the fatal error [UNRESOLVED DEPENDENCIES: base#base_2.12;0.1.0-SNAPSHOT: not found]

The thing is, the string {0.1.0-SNAPSHOT} doesn't occur anywhere in my build.sbt or anywhere else. It used to be there, but it's long gone. I assume some update cache contains it, but I've been unable to find it.

Here is my {build.sbt}:

ThisBuild / libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
ThisBuild / Compile / scalacOptions ++= Seq("--deprecation")

ThisBuild / Test / logBuffered := false
ThisBuild / Test / parallelExecution := false

lazy val scala213 = "2.13.5"
lazy val scala212 = "2.12.13"
lazy val scala3 = "3.0.0-RC2"
lazy val supportedScalaVersions = List(scala213, scala3)

lazy val root = (project in file("."))
  .aggregate(top, trans, base)
  .settings(
    name := "toysat"
  )

lazy val top = (project in file("top"))
  .settings(
    name := "main",
    scalaVersion := scala213,
    scalacOptions += "-Ytasty-reader",
    libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
  )
  .dependsOn(trans, base)

lazy val trans = (project in file("trans"))
   .settings(
     name := "trans",
     Compile / scalaVersion := scala3,
     libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
   ).
  dependsOn(base)

lazy val base = (project in file("base"))
  .settings(
    name := "base",
    scalaVersion := scala213,
    libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
   

Most questions of this ilk on stackoverflow are about downloading remotely defined modules. The problem I'm having is that sbt cannot find an obsolete version of one of my (freshly compiled) modules.

and here is the sbt command output (this is an Emacs buffer):

sbt:toysat> reload
[info] welcome to sbt 1.5.5 (AdoptOpenJDK Java 1.8.0_292)
[info] loading project definition from /Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/project
[info] loading settings for project root from build.sbt ...
[info] set current project to toysat (in build file:/Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/)
sbt:toysat> compile
[info] compiling 4 Scala sources to /Users/drewmcdermott/BIG/RESEARCH/puzzles/toystory4/toysat/base/target/scala-2.13/classes ...
[warn] 
[warn]  Note: Unresolved dependencies path:
[info] done compiling
[error] stack trace is suppressed; run last trans / update for the full output
[error] (trans / update) sbt.librarymanagement.ResolveException: Error downloading base:base_2.12:0.1.0-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/drewmcdermott/.ivy2/localbase/base_2.12/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/base/base_2.12/0.1.0-SNAPSHOT/base_2.12-0.1.0-SNAPSHOT.pom
[error] Total time: 25 s, completed Jul 28, 2021 11:06:18 PM

The 25 seconds were consumed compiling the 4 files in the base subproject, apparently successfully. I think it's when sbt tries to compile the trans subproject that it runs into trouble.

Here's a partial stack trace. It means nothing to me except that Coursier is involved.

sbt:toysat> last trans / update
[debug] not up to date. inChanged = true, force = false
[debug] Updating trans...
[warn] 
[warn]  Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading base:base_2.12:0.1.0-SNAPSHOT
[error]   Not found
[error]   Not found
[error]   not found: /Users/drewmcdermott/.ivy2/localbase/base_2.12/0.1.0-SNAPSHOT/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/base/base_2.12/0.1.0-SNAPSHOT/base_2.12-0.1.0-SNAPSHOT.pom
[error]     at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:258)
[error]     at lmcoursier.CoursierDependencyResolution.$anonfun$update$38(CoursierDependencyResolution.scala:227)
[error]     at lmcoursier.CoursierDependencyResolution$$Lambda$4262/0x0000000000000000.apply(Unknown Source)
[error]     at scala.util.Either$LeftProjection.map(Either.scala:573)
[error]     at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:227)
[error]     at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error]     at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:59)

It seems clear that some cache somewhere is holding onto the string 0.1.0-SNAPSHOT, but there are an ungodly number of caches. I've tried deleting several, but I haven't found the relevant one.

Can someone explain how to recover from a situation like this?

airfoyle
  • 443
  • 2
  • 13
  • Which project version are you compiling? (`version.sbt`) – Gaël J Jul 29 '21 at 06:28
  • So I've figured out that 0.1.0-SNAPSHOT is sbt's default version. If I set it to "3.0" in the subproject definitions, it now fails to find base:base_2.12:3.0. I guess that's progress. – airfoyle Jul 29 '21 at 16:17
  • Okay, now it makes sense. I'll explain with an answer below – Gaël J Jul 29 '21 at 16:19

2 Answers2

1

Your base project is only compiled for Scala 2.13 whereas it is defined as a dependency (using dependsOn) of trans which targets Scala 3.

You should cross-build your base project for Scala 2.13 and 3 (and maybe 2.12 according to your error message even though I don't see any use of Scala 2.12 in what you shared).

Edit: Scala 2.13 and 3 are compatible, so the issue should only happen if a dependency is built only for 2.12.

Gaël J
  • 11,274
  • 4
  • 17
  • 32
  • Thanks @GaelJ. However, I guess I don't understand what "cross-building" means. The stuff in `base` is not compatible with Scala 3, but that shouldn't be relevant, should it? Once it's compiled, it's in JVM byte code, and the stuff in `trans` (which *is* in Scala 3) should be able to run it, no? – airfoyle Jul 30 '21 at 16:03
  • It's not entirely true: Scala code is not binary compatible between 2.12 and 2.13 for instance. However Scala 2.13 and 3 are compatible to some extent (see https://docs.scala-lang.org/scala3/guides/migration/compatibility-intro.html). – Gaël J Jul 30 '21 at 16:07
  • So the actual issue is where do the "2.12" comes from because you're right 2.13 and 3.0 should work. – Gaël J Jul 30 '21 at 16:10
  • I got it to work, although I'm still not sure how. I installed the plugin sbt-projectmatrix and followed the instructions. I had to make one further change, which I do not understand, but it worked! This comment is too small for my entire build.sbt, but the projectmatrix plugin requires each subproject to be defined in this style, show for subproject `trans`, in the next comment. – airfoyle Jul 30 '21 at 19:04
0

I am not answering my own question because I'm a narcissist, but because I can't say what I want in a comment. Plus editing the original question would bury possibly useful information in an odd place. I've upvoted and approved @GaelJ's answer.

My build.sbt doesn't look that different. The differences may be encapsulated by showing the revised trans subproject definition:

lazy val trans = (projectMatrix in file("trans"))
   .settings(
     name := "trans",
     version := "0.3",
     // I thought this line was unnecessary, but without 
     // it sbt doesn't understand the command trans / compile --
     Compile / scalaVersion := scala3,
     libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.7" % Test
   )
  .jvmPlatform(scalaVersions = Seq(scala213))
  .dependsOn(base)
airfoyle
  • 443
  • 2
  • 13