-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
NoSuchMethodError thrown with Scala 2.12 #1087
Comments
I assume it's down to Java 8 and Scala 2.12 expecting to find the "init" method in the ScalaDsl.class file (new style Traits as interfaces) rather than in ScalaDsl$class.class file (old style Traits as interface and supporting class). Using javap to look at ScalaDsl.class from cucumber-scala_2.12-1.2.5.jar , I see it has MajorVersion = 50 which means it was compiled under Java 6. I think the Scala 2.12 package needs to be compiled (not just run) under Java 8 to avoid this problem. |
I've confirmed that adding this to scala/scala_2.12/pom.xml fixes the issue:
|
If you can't wait for this to be fixed in the next Cucumber release build, my advice would be:
Then change your project's build to reference cucumber-scala version 1.2.6-SNAPSHOT. From what you're saying, it sounds like you're building the Cucumber .java sources from inside your build. I'm sure you can get that to work if you need to but it doesn't seem like the obvious right thing to do (to me). |
It would help if someone could verify PR #1091, that should fix this issue. The code linked to this issue seems to be behaving in the same way (so failing the second example) with:
To try it:
|
PR #1091 fixes it for my project. Tests run successfully with Scala version 2.12.0 and 2.12.2. I confirmed before I ran with 1.2.6-SNAPSHOT (which I built locally from your pull request) that the tests were still failing as I expected with version 1.2.5. |
Hello @paoloambrosio @daveboden some date for the deployment of the solution? I need use cucumber-scala in my project. Thanks!! |
Hi. You need https://github.com/cucumber/cucumber-jvm |
Hi @paoloambrosio & @davebassan, |
I have an SBT plugin/test framework for Scala/Cucumber here https://github.com/lewismj/cucumber |
Hi, Example project: |
hi @paoloambrosio , thanks for the fix.Have tried your fix, and dont get NoMethodError anymore, but code within stepdefnition does not get executed(though the tests pass without executing code within stepdefs).They get executed, when I switch to 2.11 version of cucumber i.e 1.2.4.Can you please confirm this if this is known issue with the fix |
@Bhavana-git see #1091, says step-executions and 0-arity functions fail with scala 2.12, for that pull request. |
@stela thanks , noticed it just now. |
This still does not work for us: with 2.12 we still get the exception mentioned in the first post (by @randomcoder) and later by @lewismj:
Meanwhile, #1091 is still not merged. Is there any way to get this working with 2.12? |
I updated @randomcoder 's example to follow the transition from |
tl;dr: the root of the problem is that the Scala 2.12 support dependes on version 2.12.0-M1, as noted in a comment:
We have been struggling with this issue for some time, so I'd like to share our experience.
|
I created a GitHub repo and a Travis build that "sort of" reproduces the error: |
@szarnyasg thanks for summarizing all that! I've tried to solve the issue by building scala_2.12 module against java 8 but this break reflection. In some circumstances, I know not which, scala will compile the Steps into a Lambda rather then a class and erase the argument type information of the apply function. |
Ah right. #1091 solved that already. Does anybody have any serious objections against discontinuing support for java 8 for scala 2.12.x and up? |
#1091 was quite difficult to merge (see my attempt at https://github.com/szarnyasg/cucumber-jvm/commits/scala-2.12-with-java-8), and it only solved the NoSuchMethodError issue - I could only get it working from a projet that also uses the milestone version.
|
Eh. Typo. Meant to say that we'll only build scala 2.12.x and up for java 8.
Good. I was under the impression it could also work with 7. |
I've updated This seems to resolve the problems. |
I still have to test this against the reproducers but #1171 is passing my tests locally. |
This appears to be a feature of Scala. When("""^I multiply x \* y$""") {
z = x * y
} Will execute the statement On the other hand When("""^I multiply x \* y$""") { () =>
z = x * y
} Will return a function with the signature *Apologies if this explanation is a bit sloppy or even wrong. Not that into Scala. :) |
I was wrong. The first example utilizes call by name, the second call by reference. We allow both. The original PR broke call by name. This has been fixed. |
What is the expected out come of the reproducer. It is currently failing because the steps instance is reused between examples in the scenario. This is a bug, but the behavior also appears to have been present for a long while. |
@mpkorstanje Unfortunately, I am not an expert at Cucumber, so I cannot answer this. |
Then I'll consider it passing. The tests are running at least. |
Thanks, this is great news, any idea when it may be in the SNAPSHOT build? |
Propagation delays aside it should be available right now. Do note the changed groupId
|
Great, the tests now work at https://travis-ci.org/szarnyasg/cucumber-scala-2-12. Thanks @mpkorstanje! |
thanks @mpkorstanje! , looks good with oracle java 8 + scala 2.12.2 + cucucumber-scala 2.0.0-SNAPSHOT |
Thanks, this fixed my issue: lewismj/cucumber#28 , published an update for my sbt plugin to nexus. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
When running cucumber tests with
cucumber-scala
(1.2.5) using Scala 2.12.1 or 2.12.0 anoSuchMethodError
is raised on startupHere is a minimal project that reproduces the behaviour: https://github.com/randomcoder/cucumber-scala-2-12
Expected Behavior
The test cases should run
Current Behavior
The error below is thrown before any tests are executed
Steps to Reproduce (for bugs)
sbt "run --dry-run --glue steps classpath:feature"
The text was updated successfully, but these errors were encountered: