cucumber-jvm: NoSuchMethodError thrown with Scala 2.12
Summary
When running cucumber tests with cucumber-scala (1.2.5) using Scala 2.12.1 or 2.12.0 a noSuchMethodError is raised on startup
Here 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
Exception in thread "main" java.lang.NoSuchMethodError: cucumber.api.scala.ScalaDsl.$init$(Lcucumber/api/scala/ScalaDsl;)V
at steps.SimpleScenarioSteps.<init>(SimpleScenarioSteps.scala:6)
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 java.lang.Class.newInstance(Class.java:442)
at cucumber.runtime.scala.ScalaBackend$$anonfun$6.apply(ScalaBackend.scala:62)
at cucumber.runtime.scala.ScalaBackend$$anonfun$6.apply(ScalaBackend.scala:62)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at scala.collection.TraversableLike.map$(TraversableLike.scala:234)
at scala.collection.AbstractTraversable.map(Traversable.scala:104)
at cucumber.runtime.scala.ScalaBackend.loadGlue(ScalaBackend.scala:62)
at cucumber.runtime.Runtime.<init>(Runtime.java:92)
at cucumber.runtime.Runtime.<init>(Runtime.java:70)
at cucumber.runtime.Runtime.<init>(Runtime.java:66)
at cucumber.api.cli.Main.run(Main.java:35)
at cucumber.api.cli.Main.main(Main.java:18)
Steps to Reproduce (for bugs)
- In the sample project execute
sbt "run --dry-run --glue steps classpath:feature"
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 6
- Comments: 34 (11 by maintainers)
Commits related to this issue
- [Scala] Compile cucumber-scala_2.12 against java8 - cucumber-scala_2.12 and scala-calculator are compiled to java8 byte code - Scala versions have been updated - 2.12.0-M1 to 2.12.2 - 2.11.8 ... — committed to cucumber/cucumber-jvm by mpkorstanje 7 years ago
- [Scala] Compile cucumber-scala_2.12 against java8 - cucumber-scala_2.12 and scala-calculator are compiled to java8 byte code - Scala versions have been updated - 2.12.0-M1 to 2.12.2 - 2.11.8 ... — committed to cucumber/cucumber-jvm by mpkorstanje 7 years ago
- [Scala] Compile cucumber-scala_2.12 against java8 - cucumber-scala_2.12 and scala-calculator are compiled to java8 byte code - Scala versions have been updated - 2.12.0-M1 to 2.12.2 - 2.11.8 ... — committed to cucumber/cucumber-jvm by mpkorstanje 7 years ago
thanks @mpkorstanje! , looks good with oracle java 8 + scala 2.12.2 + cucucumber-scala 2.0.0-SNAPSHOT https://github.com/jecklgamis/cucumber-jvm-scala-example
Propagation delays aside it should be available right now.
Do note the changed groupId
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.
@randomcoder’s original post has a small issue: instead of
feature, it should befeatureson the classpath:@paoloambrosio’s comment is correct and I could get the example in the issue working.
With @szdavid92, we created a fork from @paoloambrosio’s
scala-2.12-with-java-8branch, merged this repository’s currentmasterbranch and resolved the conflicts. This resulted in a working version, which is available on my fork. This works with @randomcoder’s example, provided that thecucumber-scala-2-12project also uses the milestone Scala version, else it will throw the error mentioned in the original post:While this might seems a plausible approach, unfordunately
mvn -pl scala/scala_2.12 -am installdoes not compile it - instead, it throws a ton of errors. Hence, I see no point of raising a PR from this.Simply using the current
2.0.0-SNAPSHOT(as deployed in the Sonatype OSS Snapshots repository) returns in the following error:We tried to fix this by explicitly adding the appropriate Scalactic dependency (
"org.scalactic" % "scalactic_2.12" % "3.0.3"), but it made no difference.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
Hi, I still get this error, using 1.2.6-SNAPSHOT, java.lang.NoSuchMethodError: cucumber.api.scala.ScalaDsl.$init$(Lcucumber/api/scala/ScalaDsl
Example project: https://github.com/lewismj/cucumber
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:
mvn clean installresolvers += Resolver.mavenLocal)