在build.sbt中导入Flink-Scala API时遭遇依赖解析错误
Problem Description
I tried to import the Flink Scala API in my build.sbt with the following configuration:
name := "flink_stream" version := "0.1" scalaVersion := "2.12.4" // https://mvnrepository.com/artifact/org.apache.flink/flink-scala libraryDependencies += "org.apache.flink" %% "flink-scala" % "1.4.0"
But when running, I got this error:
sbt.librarymanagement.ResolveException: unresolved dependency: org.apache.flink#flink-scala_2.12;1.4.0: not found [后续错误栈信息原文保留]
What's wrong with my configuration?
Solution
Let’s break down exactly why you’re hitting this unresolved dependency issue, and how to fix it:
1. The Root Cause: Scala Version Compatibility
Apache Flink 1.4.0 does not support Scala 2.12. If you look into Flink’s release history, versions 1.4.x only officially support Scala 2.11. Scala 2.12 support wasn’t added to Flink until version 1.7.0. That’s why sbt can’t find the flink-scala_2.12;1.4.0 artifact—it never existed in Maven Central.
2. Two Fix Options to Choose From
You have two straightforward paths to resolve this:
Option 1: Downgrade Scala to match Flink 1.4.0
Stick with Flink 1.4.0, but update your Scala version to a compatible 2.11 release (like 2.11.12, which is a stable, widely used 2.11 version). Modify yourscalaVersionline in build.sbt:scalaVersion := "2.11.12"Option 2: Upgrade Flink to support Scala 2.12
Keep your current Scala 2.12.4 version, and upgrade Flink to a release that supports it. I’d recommend using a recent stable Flink version (like 1.17.1) to get bug fixes, performance improvements, and newer features. Update your dependency line:libraryDependencies += "org.apache.flink" %% "flink-scala" % "1.17.1"
3. Quick Check: Your Dependency Syntax is Correct
Just to confirm—your use of %% in the dependency declaration is perfect. This syntax automatically appends your project’s Scala version suffix to the artifact ID, which is exactly what you need for Scala-specific Flink libraries. That part wasn’t causing the issue here.
内容的提问来源于stack exchange,提问作者softshipper

