Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems running akka-http using Kotlin #1168

Closed
Gabology opened this issue May 29, 2017 · 13 comments
Closed

Problems running akka-http using Kotlin #1168

Gabology opened this issue May 29, 2017 · 13 comments
Labels
0 - new Ticket is unclear on it's purpose or if it is valid or not t:java Issues related to the Java DSL t:routing Issues related to the routing DSL

Comments

@Gabology
Copy link
Contributor

Attempting to write tests using Maven is yielding the following error:

java.lang.NoClassDefFoundError: org/scalactic/TripleEqualsSupport$class

	at akka.http.javadsl.testkit.JUnitRouteTestBase.<init>(JUnitRouteTest.scala:24)
	at akka.http.javadsl.testkit.JUnitRouteTest.<init>(JUnitRouteTest.scala:54)
	at AppTest.<init>(AppTest.kt:11)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
	at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.scalactic.TripleEqualsSupport$class
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
...

Minimal code to reproduce is as follows:

class AppTest : JUnitRouteTest() {
    private val appRoute : TestRoute = testRoute(App.route())
}

I have added both scalatest_2.12 and junit as test dependencies. Running mvn clean does not seem to have have helped.

@ktoso
Copy link
Member

ktoso commented May 29, 2017

Please show your dependencies section

@Gabology
Copy link
Contributor Author

Dependecies

   <dependencies>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jre8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-http-core_2.11</artifactId>
            <version>10.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-http_2.11</artifactId>
            <version>10.0.6</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-parsing_2.11</artifactId>
            <version>10.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.12</artifactId>
            <version>3.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-http-testkit_2.11</artifactId>
            <version>10.0.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

@ktoso
Copy link
Member

ktoso commented May 29, 2017

The scala major version must match for all artifacts (that's the major one released every few years).

You said you included scalatest_2.12 but you're using Akka 2.11. Use all artifacts from 2.12.
Put it in a variable: scala.version and add it to all artifact names like <artifactId>akka-http-testkit_${scala.binary.version}</artifactId>

@Gabology
Copy link
Contributor Author

@ktoso Thanks, however now this error being produced instead:

java.lang.UnsupportedOperationException: empty.reduceLeft

	at scala.collection.TraversableOnce.reduceLeft(TraversableOnce.scala:180)
	at scala.collection.TraversableOnce.reduceLeft$(TraversableOnce.scala:178)
	at scala.collection.mutable.ArrayBuffer.scala$collection$IndexedSeqOptimized$$super$reduceLeft(ArrayBuffer.scala:48)
	at scala.collection.IndexedSeqOptimized.reduceLeft(IndexedSeqOptimized.scala:56)
	at scala.collection.IndexedSeqOptimized.reduceLeft$(IndexedSeqOptimized.scala:72)
	at scala.collection.mutable.ArrayBuffer.reduceLeft(ArrayBuffer.scala:48)
	at scala.collection.TraversableOnce.reduce(TraversableOnce.scala:208)
	at scala.collection.TraversableOnce.reduce$(TraversableOnce.scala:208)
	at scala.collection.AbstractTraversable.reduce(Traversable.scala:104)
	at akka.http.javadsl.server.directives.RouteDirectives.route(RouteDirectives.scala:46)
	at akka.http.javadsl.server.directives.RouteDirectives.route(RouteDirectives.scala:43)
	at AppTest.<init>(AppTest.kt:12)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:217)
	at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:266)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

@jrudolph
Copy link
Member

That means that your route has somewhere a part like this: route() with zero arguments. We should improve the error message or even better make it illegal to use it like this. I'll create another ticket for that.

@jrudolph
Copy link
Member

I created #1170 to track the route issue. I'll close this one for now as the maven problem seems to be solved.

@Gabology
Copy link
Contributor Author

@jrudolph I don't see how that is the case here, I tried it with the most minimal path and I'm still getting the same error.

object App : HttpApp() {
    override fun route() : Route = route(
        path("/hello", { get { complete("Hello from Akka HTTP!") } })
    )
}

fun main(args: Array<String>) {
    App.startServer("0.0.0.0", 8080)
}

@jlprat
Copy link
Member

jlprat commented May 29, 2017

maybe some name clashing with both route methods?
Does it happen as well on 10.0.7? Note the method to override on HttpApp is routes then.

@jrudolph jrudolph changed the title NoClassDefFoundError on w/ Maven Problems running akka-http using Kotlin May 29, 2017
@jrudolph
Copy link
Member

@OverlyExcessive interesting maybe it's some kotlin incompatibility? Can you post a complete example somewhere including all instructions how to build? E.g. maven would be great. Let's use this ticket to fix that problem.

@jrudolph jrudolph reopened this May 29, 2017
@jrudolph jrudolph added 0 - new Ticket is unclear on it's purpose or if it is valid or not t:java Issues related to the Java DSL t:routing Issues related to the routing DSL labels May 29, 2017
@Gabology
Copy link
Contributor Author

Gabology commented May 30, 2017

@jlprat

Omitting route and just leaving it with a single path directive produces the same error so alas this does not seem to be the case.

@jrudolph

I uploaded a minimal example to a repository here. You can build it running mvn test.

Thanks for your diligence in this.

@raboof
Copy link
Member

raboof commented May 30, 2017

HttpApp extends RouteDirectives, and it seems App.route() in your test is calling RouteDirectives.route() instead of the route() in your App because the latter is protected rather than public.

That's indeed quite confusing, luckily in 10.0.7 we've renamed HttpApp.route to HttpApp.routes, removing this confusion.

After this change mvn still complains about the main method, but that probably has nothing to do with akka-http :).

@Gabology
Copy link
Contributor Author

@raboof Yep that seems to have fixed it. Thanks!

@jrudolph
Copy link
Member

Thanks for checking, @raboof, I didn't see that AppTest was posted before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 - new Ticket is unclear on it's purpose or if it is valid or not t:java Issues related to the Java DSL t:routing Issues related to the routing DSL
Projects
None yet
Development

No branches or pull requests

5 participants