6

I am trying to launch a cucumber (written in kotlin) via intellij.

I have a step definition class described as followed :

enter image description here

When I launch the test from Intellij, I have this Exception on the "Given" method: java.lang.IllegalStateException: Could resolve the return type of the lambda at BusinessEventSteps.kt:19

enter image description here

When using "mvn clean install" from a command line, the test runs fine.

My environment:

  • MacOS
  • Coretto 11.0.11
  • Intellij 2021.1.1
  • Kotlin 1.4.10
  • cucumber 6.10.4
GrassHopper
  • 116
  • 5
  • 2
    Cucumber is fishing in the constant pool to determine the type of the types of the lambda. Looks like Correto has an unexpected layout. I doubt that can be fixed easily or at all. That means you have to use `cucumber-java` with Kotlin instead of `cucumber-java8`. – M.P. Korstanje Jun 01 '21 at 16:00
  • Well, the weird thing is that it works using mvn in command line, and it also works on a collegue's PC, which only difference I see is he is on Windows. So I'm not sure that it has anything to do with the cucumber library. – GrassHopper Jun 02 '21 at 08:25
  • It depends on the JVM that is used. Your IDE, maven and colleague are probebly using different JVMs. – M.P. Korstanje Jun 02 '21 at 08:33
  • Nope unfortunately we both have the same Intellij version, coretto and maven version :/ – GrassHopper Jun 02 '21 at 09:36
  • I would try to verify that very carefully. Within IDEA you have to choice of selecting different JVMs again. – M.P. Korstanje Jun 02 '21 at 09:37
  • How do you explain though that it works with coretto by running the tests through "mvn test" command line ? I guess it has to be an IDE issue but i can't find out. – GrassHopper Jun 02 '21 at 10:22
  • The root cause depends on implementation details of the JVM. So if it works in one situation and not the other, it follows that you have a different JVM. Alternatively you've got stale caches in IDEA but I assume you already ruled that out. – M.P. Korstanje Jun 02 '21 at 10:36
  • Thanks for your help, I have found a workaround (still don't understand why this happens though). Check out my post edit. It seems to be an issue with the native IDEA compiler. – GrassHopper Jun 02 '21 at 16:07
  • 1
    You can post your solution as an answer. – M.P. Korstanje Jun 02 '21 at 22:46
  • 1
    And not a clue, why other then what I said. Cucumber Java8 depends on implementation details in the JVM. If IDEA doesn't match on those details it won't work – M.P. Korstanje Jun 02 '21 at 22:47
  • Yeah I knew it was definetly an Intellij issue, so I started searching around about how does Intellij builds the application and on their documentation they stand: "However, IntelliJ IDEA native builder might not correctly build the Gradle or Maven project if its build script file uses custom plugins or tasks". This is the first time I have to customize the default intellij build mechanism. Anyway, thanks for your help ! – GrassHopper Jun 03 '21 at 07:27

1 Answers1

4

Found a workaround. It seems that the issue has something to do with the native Intellij compiler. Editing the Run/Debug Configurations and replacing the default "Build" step by a maven goal, everything works fine.

Hope this will help others !

enter image description here

GrassHopper
  • 116
  • 5