Scala新手求助:如何解决SBT中的依赖无法解析问题?
Hey there! As a fellow Scala/SBT user, let's walk through why your dependency isn't resolving and get it fixed.
First, let's clean up your build.sbt syntax—there are a couple of small issues that might be causing problems right off the bat:
Corrected build.sbt Code
name := "scalaTest" version := "0.1" // Note the capital D in libraryDependencies, and += instead of := libraryDependencies += "com.github.mmnu" %% "scalafh" % "0.1-SNAPSHOT"
Key Fixes Here:
- Variable Name Case: It's
libraryDependencies(capital D), not lowercaselibrarydependencies—SBT is case-sensitive for these built-in settings. - Append Instead of Overwrite: Use
+=instead of:=forlibraryDependencies—this adds your new dependency to the existing set of dependencies, rather than replacing the entire list (which would break default Scala library dependencies).
Next: Add Snapshot Repository Access
Snapshot versions like 0.1-SNAPSHOT aren't hosted on Maven Central by default. You need to tell SBT where to look for this snapshot. Most GitHub-hosted Scala projects use either JitPack or Sonatype Snapshots for their snapshot builds. Add one or both of these resolvers to your build.sbt:
// Add JitPack (common for GitHub projects) resolvers += "JitPack" at "https://jitpack.io" // Add Sonatype Snapshots (used by many Scala open-source projects) resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
Final Steps to Verify
- Double-check the dependency coordinates: Make sure
com.github.mmnu,scalafh, and0.1-SNAPSHOTare exactly correct—typos here are the #1 cause of resolution failures. - Refresh your SBT project: Run
updatein the SBT console, or use your IDE's "Refresh SBT Project" option to pull in the new dependency and repository settings.
If you still run into issues, confirm that the project scalafh actually publishes snapshot versions to one of these repositories—some projects only release stable versions.
内容的提问来源于stack exchange,提问作者J Doe

