IntelliJ IDEA 2023.3 Help

Enable Cucumber support

To be able to use Cucumber in your application, make sure that the necessary plugins are enabled and add the Cucumber library to your project.

Enable plugins

In IntelliJ Ultimate, the required plugins are bundled and enabled by default. However, we recommend you to make sure that they are switched on.

In IntelliJ Community, the necessary plugins are not bundled, that is why you need to install and enable them.

  1. Press Ctrl+Alt+S to open the IDE settings and then select Plugins.

  2. Switch to the Installed tab and make sure that the following plugins are enabled (the plugins must be enabled in the specified order):

    • Gherkin

    • Cucumber for Java

    • Cucumber for Groovy (optional: install this plugin if you want to create step definitions in Groovy)

  3. If the plugins are not installed, switch to the Marketplace tab, type their names in the search field in the specified order, and click Install next to each of them.

  4. Apply the changes and close the dialog. Restart the IDE if prompted.

Enabling the Cucumber plugin in the settings

Add the Cucumber library

Follow these steps to add a library if you're building your project with the native IntelliJ IDEA builder:

  1. In the main menu, go to File | Project Structure (Ctrl+Alt+Shift+S).

  2. Under Project Settings, select Libraries and click the New Project Library button | From Maven.

  3. In the dialog that opens, specify the artifact of the library version that you want to use in your project, for example: io.cucumber:cucumber-java:jar:6.1.1 or io.cucumber:cucumber-java8:jar:6.1.1 (if you want to use lambda expressions in step definitions).

    Click OK.

  4. Apply the changes and close the dialog.

    Adding a Cucumber library to a project

Follow these steps if you're using Maven in your project:

  1. In your pom.xml, add the following dependencies (make sure to specify the latest version of Cucumber):

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

    Alternatively, if you want to use lambda expressions in step definitions, add:

    <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java8</artifactId> <version>6.1.1</version> <scope>test</scope> </dependency>
  2. Press Ctrl+Shift+O or click Reimport All Maven Projects in the Maven tool window to import the changes.

For more information about working with Maven, refer to Maven dependencies.

Use these steps if you're building your project with Gradle.

  1. Open your build.gradle and add the following dependencies (make sure to specify the latest version of Cucumber):

    For Gradle 5 and later, add:

    dependencies { testImplementation 'io.cucumber:cucumber-java:6.1.1' }

    Alternatively, if you want to use lambda expressions in step definitions, add:

    dependencies { testImplementation 'io.cucumber:cucumber-java8:6.1.1' }

    For Gradle 4.10.3 and earlier, add:

    dependencies { testCompile 'io.cucumber:cucumber-java:6.1.1' }

    Alternatively, if you want to use lambda expressions in step definitions, add:

    dependencies { testCompile 'io.cucumber:cucumber-java8:6.1.1' }

    To find out your Gradle version, run ./gradlew --version in the Terminal (Alt+F12).

  2. When the dependencies are added to your build.gradle, press Ctrl+Shift+O or click Reimport All Gradle Projects in the Gradle tool window to import the changes.

Prepare folder structure

Make sure that your project has the following folders:

Folder structure for a Cucumber project
Last modified: 19 March 2024