执行GitHub克隆的Scala程序时sbt run出现UNRESOLVED DEPENDENCIES警告
First, let's break down exactly what's happening with those warnings:
- The core problem is that sbt can't locate the specified Akka dependency versions:
akka-actor_2.11;2.4-SNAPSHOT,akka-contrib_2.11;2.4-SNAPSHOT, andakka-testkit_2.11;2.4-SNAPSHOT. SNAPSHOTversions are development-only "work-in-progress" builds. They’re almost never published to public repositories like Maven Central (the repo you see in the download logs), so sbt has no way to pull them down.- From the error path, these dependencies are either defined directly in your project’s
build.sbtfile, or are required by theactoverse-for-akkalibrary your project depends on.
Here are actionable steps to fix this:
1. Replace SNAPSHOT versions with stable releases
Since you already successfully downloaded akka-stream_2.11-2.4.14, use that same stable version for the missing Akka dependencies:
- Open your project’s
build.sbtfile. - Look for lines declaring these Akka dependencies, which will look similar to:
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.4-SNAPSHOT" libraryDependencies += "com.typesafe.akka" %% "akka-contrib" % "2.4-SNAPSHOT" libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % "2.4-SNAPSHOT" - Replace
"2.4-SNAPSHOT"with"2.4.14"for all three lines, matching the version of akka-stream that worked.
2. Fix dependencies from the third-party actoverse-for-akka library
If the SNAPSHOT dependencies are coming from actoverse-for-akka (not your own build.sbt):
- Check if the
actoverse-scalarepository you cloned has recent updates. The maintainers might have already fixed this dependency issue—pull the latest code and try again. - If no updates are available, force sbt to use the stable 2.4.14 version by adding this to your
build.sbt:
This tells sbt to ignore the library’s requested SNAPSHOT version and use the stable one instead.dependencyOverrides ++= Seq( "com.typesafe.akka" %% "akka-actor" % "2.4.14", "com.typesafe.akka" %% "akka-contrib" % "2.4.14", "com.typesafe.akka" %% "akka-testkit" % "2.4.14" )
3. (Last resort) Add the snapshot repository (unlikely to work for old versions)
If you must use the 2.4-SNAPSHOT version (though this isn’t recommended for outdated releases), add the Sonatype snapshot repository to your build.sbt:
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
Note: Older SNAPSHOT versions like 2.4-SNAPSHOT are often removed from repositories over time, so this might not work. Stick to stable releases first.
After making these changes, run sbt clean run to clear cached dependency data and try building again.
内容的提问来源于stack exchange,提问作者f_s

