Search code examples
javagradleakkaakka-streamakka-http

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


Here is the 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"))
                                        )
                        )
                );
    }

}

Here are the dependenices in 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'

I am not sure why this error occures even though I referred here and found that these versions should be compatible as mentioned in the docs link below:

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

unfortunately I cannot update the akka version it has to be 2.5.14 since it is the version of the parent project and changing that might break things in other child projects. Is there anyway I can make akka http work with akka version 2.5.14?

Here is the complete stacktrace:

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)

The line numbers will vary since I had to censor some code.


Solution

  • The issue was not with akka but with stale dependencies in my project.

    I had earlier tried to use

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

    Which must have downloaded the dependency and was being used to start the project.

    I did gradle --refresh-dependencies which fixed the problem.

    Make sure you view the docs to see the compatibility of the modules and clean cache and re-download all the dependencies.