Scala 2.13版本下Play框架Anorm依赖未解决的解决方法
Let's break down why you're hitting that sbt.librarymanagement.ResolveException and how to fix it:
Why the Error Happens
The Anorm version you're using (2.3.9) is extremely outdated—it's tied to Play Framework 2.3.x, which only supports Scala 2.10 and 2.11. When you use %% in your sbt dependency, it automatically appends your project's Scala version (2.13) to the artifact name, so sbt tries to find anorm_2.13:2.3.9. Since this artifact was never published (maintainers never built Anorm 2.3.9 for Scala 2.13), sbt can't resolve it.
Solutions
1. Upgrade Anorm to a Scala 2.13-Compatible Version
Anorm was later split off from the Play Framework into its own standalone library with a new group ID. To use a version that supports Scala 2.13:
Replace your existing dependency with a modern, compatible release. For example:
libraryDependencies += "org.playframework.anorm" %% "anorm" % "2.6.10"(Any release from
2.6.0onwards supports Scala 2.13; you can use newer versions if available.)Important: Since this is a standalone Anorm, you'll need to update your code's import statements. Replace old imports like
import play.api.db.anorm._withimport anorm._. Some API details may have changed from the Play-bound version, so you might need to adjust your code slightly.
2. Downgrade Scala to a Version Supported by Anorm 2.3.9
If you absolutely must stick with Anorm 2.3.9 (e.g., your project is locked to Play 2.3.x), you'll need to downgrade your Scala version to either 2.10 or 2.11. Add this to your build.sbt:
scalaVersion := "2.11.12"
This is the most recent stable release of Scala 2.11, fully compatible with Anorm 2.3.9.
Final Notes
Unless you have a hard requirement for the old Play 2.3.x ecosystem, upgrading to the standalone Anorm is the better long-term solution—it gives you bug fixes, new features, and compatibility with modern Scala versions.
内容的提问来源于stack exchange,提问作者koko ka

