Search code examples
javaintellij-ideacucumbernoclassdeffounderror

IntelliJ and cucumber not working


I'm using IntelliJ Idea Ultimate 2018.1 and in my java project, I've some BDD implemented with Cucumber and Gherkin. when I try to right-click on a feature file and run it I see the following error

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/formatter/Formatter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:174)
    at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:166)
    at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:223)
    at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:206)
    at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:456)
    at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:160)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:112)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:105)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:97)
    at cucumber.api.cli.Main.run(Main.java:30)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: gherkin.formatter.Formatter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

This is happening for some days. In the past was working perfectly. The cucumber for java and gherkin plugins are installed. I've tried to download a new fresh version of IntelliJ but no luck.

The dependencies I've in my project are the following

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

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

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

and my feature file is similar to the following

Feature: Blocker Accumulation

Scenario: Blocker Accumulation
    Given I am logged as a user
    And I have an In-progress activity
    And it has been previously blocked for 16 days
    And now is not blocked
    When I block the activity for other more 6 days
    Then the total blocking days is 22

What can I try? What's my fault? Thank you


Solution

  • The problem was a compatibility issue between cucumber 3 and the intelliJ cucumber plugin.

    In order to make everything working I have changed the cucumber.version value from 3.0.2 to 2.4.0.