akka.UnsupportedAkkaVersion: Like 的当前版本是 [2.5.14],但是 like-http 需要版本 [2.5.26]

akka.UnsupportedAkkaVersion: Current version of Akka is [2.5.14], but akka-http requires version [2.5.26]

这是class:

import akka.Done;
import akka.NotUsed;
import akka.actor.ActorSystem;
import akka.http.javadsl.ConnectHttp;
import akka.http.javadsl.Http;
import akka.http.javadsl.model.ContentTypes;
import akka.http.javadsl.model.HttpEntities;
import akka.http.javadsl.model.HttpHeader;
import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.HttpResponse;
import akka.http.javadsl.server.AllDirectives;
import akka.http.javadsl.server.Route;
import akka.stream.ActorMaterializer;
import akka.stream.javadsl.Flow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

public class Ge extends AllDirectives
{

    private static String host = "localhost";
    private static int port = 8080;
    private static List<HttpHeader> headers;


    public static void main(String[] args) throws Exception
    {
        // boot up server using the route as defined below
        ActorSystem system = ActorSystem.create();

        final ActorMaterializer materializer = ActorMaterializer.create(system);
        final Http http = Http.get(system);
        //In order to access all directives we need an instance where the routes are define.

        Ge ge = new Ge();

        final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = gridUpdateService.createRoute().flow(system, materializer);

        http.bindAndHandle(routeFlow,
                ConnectHttp.toHost(host, port), materializer);

    }

    private Route createRoute()
    {
        return  route(
                        path(
                                "spec", () ->
                                        get(() -> complete(HttpEntities.create(ContentTypes.TEXT_PLAIN_UTF8, "Ok"))
                                        )
                        )
                );
    }

}

以下是 build.gradle 中的依赖项:

compile group: 'com.typesafe.akka', name: 'akka-http_2.12', version: '10.1.5'
compile group: 'com.typesafe.akka', name: 'akka-cluster_2.12', version: '2.5.14'

我不确定为什么会出现此错误,尽管我在此处提到并发现这些版本应该兼容,如下面的文档 link 中所述:

Compatibility with Akka Akka HTTP 10.1.x is (binary) compatible with Akka >= 2.5.11 and future Akka 2.x versions that are released during the lifetime of Akka HTTP 10.1.x.

https://doc.akka.io/docs/akka-http/current/compatibility-guidelines.html

不幸的是,我无法更新 akka 版本,它必须是 2.5.14,因为它是父项目的版本,更改可能会破坏其他子项目中的内容。无论如何我可以让 akka http 与 akka 版本 2.5.14 一起工作吗?

这是完整的堆栈跟踪:

Exception in thread "main" akka.UnsupportedAkkaVersion: Current version of Akka is [2.5.14], but akka-http requires version [2.5.26]
    at akka.AkkaVersion$.require(AkkaVersion.scala:43)
    at akka.AkkaVersion$.require(AkkaVersion.scala:23)
    at akka.http.scaladsl.HttpExt.<init>(Http.scala:57)
    at akka.http.scaladsl.Http$.createExtension(Http.scala:1123)
    at akka.http.scaladsl.Http$.createExtension(Http.scala:892)
    at akka.actor.ActorSystemImpl.registerExtension(ActorSystem.scala:913)
    at akka.actor.ExtensionId.apply(Extension.scala:79)
    at akka.actor.ExtensionId.apply$(Extension.scala:78)
    at akka.http.scaladsl.Http$.apply(Http.scala:1118)
    at akka.http.scaladsl.Http$.apply(Http.scala:892)
    at akka.http.javadsl.Http.delegate$lzycompute(Http.scala:45)
    at akka.http.javadsl.Http.delegate(Http.scala:45)
    at akka.http.javadsl.Http.defaultServerHttpContext(Http.scala:852)
    at akka.http.javadsl.Http.bindAndHandle(Http.scala:232)
    at com.dummy.ui.Ge.startHttp(Ge.java:55)

行号会有所不同,因为我不得不审查一些代码。

问题不在于 akka,而在于我的项目中陈旧的依赖关系。

我之前曾尝试使用

compile group: 'com.typesafe.akka', name: 'akka-http_2.13', version: '10.1.5'

它一定已经下载了依赖项并被用来启动项目。

我做了 gradle --refresh-dependencies 解决了问题。

确保查看文档以查看模块的兼容性并清理缓存并重新下载所有依赖项。