cucumber throwing java.lang.NoClassDefFoundError: io/cucumber/core/gherkin/FeatureParser

I’m learning Cucumber and I’m getting the FeatureParser error

If you follow the 10 minute tutorial you’ll get an introduction that uses Maven dependency management.

In addition to this tutorial I would strongly urge you to invest time in learning either Maven or Gradle along with Cucumber. Amongst other things these tools will automate your dependency management and this can make your life much easier.

For example:

If you want to use Cucumber with JUnit 4 and annotation based step definitions you would declare this minimal set of dependencies in a Maven pom.xml file.

    <properties>
        <cucumber.version>5.2.0</cucumber.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

By telling Maven what your dependencies are Maven can calculate your transitive dependencies i.e: the dependencies of your dependencies.

This has many advantages. One example would be using the mvn dependency:tree -Dverbose=true command to will list all dependencies. This is much faster and much less error prone then downloading jar files by hand and hoping that you have the right ones.

$ mvn dependency:tree -Dverbose=true 
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------< cucumber:cucumber-java-skeleton >-------------------
[INFO] Building Cucumber-Java Skeleton 0.0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ cucumber-java-skeleton ---
[INFO] cucumber:cucumber-java-skeleton:jar:0.0.1
[INFO] +- io.cucumber:cucumber-java:jar:5.2.0:test
[INFO] |  +- io.cucumber:cucumber-core:jar:5.2.0:test
[INFO] |  |  +- io.cucumber:cucumber-gherkin:jar:5.2.0:test
[INFO] |  |  +- io.cucumber:cucumber-gherkin-vintage:jar:5.2.0:test
[INFO] |  |  +- io.cucumber:tag-expressions:jar:2.0.4:test
[INFO] |  |  +- io.cucumber:cucumber-expressions:jar:8.3.1:test
[INFO] |  |  +- io.cucumber:datatable:jar:3.3.0:test
[INFO] |  |  +- io.cucumber:cucumber-plugin:jar:5.2.0:test
[INFO] |  |  \- io.cucumber:docstring:jar:5.2.0:test
[INFO] |  \- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] +- io.cucumber:cucumber-junit:jar:5.2.0:test
[INFO] \- junit:junit:jar:4.13:test
[INFO]    \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.781 s
[INFO] Finished at: 2020-02-10T23:00:14+01:00
[INFO] ------------------------------------------------------------------------

Leave a Comment