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)

  1. 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

Most upvoted comments

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

<repository>
    <id>sonatype-snapshots</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    <snapshots>
        <enabled>true</enabled>
    </snapshots>
</repository>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>2.0.0-SNAPSHOT</version>
    <scope>test</scope>
</dependency>

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:

    <properties>
        <!--
        Upgrading to 2.12.0-M2 or higher causes:
        initializationError(cucumber.runtime.scala.test.RunCukesTest)  Time elapsed: 0.006 sec  <<< ERROR! java.util.NoSuchElementException: next on empty iterator [no stack trace] -->
        <scala.version>2.12.0-M1</scala.version>
    </properties>

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 be features on the classpath:

    sbt "run --dry-run --glue steps classpath:features"
    
  • @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-8 branch, merged this repository’s current master branch and resolved the conflicts. This resulted in a working version, which is available on my fork. This works with @randomcoder’s example, provided that the cucumber-scala-2-12 project also uses the milestone Scala version, else it will throw the error mentioned in the original post:

    java.lang.NoSuchMethodError: cucumber.api.scala.ScalaDsl.$init$(Lcucumber/api/scala/ScalaDsl;)V
    

    While this might seems a plausible approach, unfordunately mvn -pl scala/scala_2.12 -am install does 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:

    [error] (run-main-0) java.lang.NoClassDefFoundError: org/scalactic/TripleEqualsSupport$class java.lang.NoClassDefFoundError: org/scalactic/TripleEqualsSupport$class
    

    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:

  • Scala 2.12.1 and cucumber-scala 1.2.6-SNAPSHOT form the PR
  • Scala 2.11.8 and cucumber-scala 1.2.5

To try it:

  • From the code root of the PR
    • Run mvn clean install
  • In your project
    • Change cucumber-scala from 1.2.5 to 1.2.6-SNAPSHOT
    • If using SBT, add the local Maven repository (resolvers += Resolver.mavenLocal)