Java Tools

This page describes tools commonly used with Java.

IDEs 🔗︎

IntelliJ IDEA 🔗︎

You can find more information on using Cucumber with IntelliJ IDEA in the IntelliJ IDEA Cucumber help pages

Eclipse 🔗︎

Build tools 🔗︎

The most widely used build tools for Java are Maven and Gradle.

Maven 🔗︎

To run Cucumber with Maven, make sure that:

  • Maven is installed
  • The environment variable MAVEN_HOME is correctly configured
  • The IDE is configured with the latest Maven installation

Steps:

  1. Create a new Maven project or fork cucumber-java examples on Github
  2. Add the following dependency to the pom.xml

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.2.5</version>
    </dependency>
  3. Add feature .feature files and associated step mapping classes .java in src/test/resources and src/test/java folders respectively.

  4. Run the following Maven from the directory path where the pom.xml file is located:

    mvn clean install -DCucumberOptions="--glue package_name_of_step_definitions \
       --plugin pretty path\to\featurefiles"

Gradle 🔗︎

To run Cucumber with Gradle, make sure that:

  • Gradle is installed
  • The environment variable GRADLE_HOME is correctly configured
  • The IDE is configured with the latest Gradle installation

Steps:

  1. Create a new Gradle project or look at java-gradle example on Github
  2. Add the following dependency to build.gradle

    dependencies {
        testCompile 'io.cucumber:cucumber-java:4.2.5'
    }
    
  3. Add the following configuration to build.gradle

    configurations {
        cucumberRuntime {
            extendsFrom testRuntime
        }
    }
    
  4. Add feature .feature files and associated step mapping classes .java in src/test/resources and src/test/java respectively in a gradle.cucumber package.

  5. Add the following Gradle cucumber task in build.gradle

    task cucumber() {
        dependsOn assemble, compileTestJava
        doLast {
            javaexec {
                main = "cucumber.api.cli.Main"
                classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
                args = ['--plugin', 'pretty', '--glue', 'gradle.cucumber', 'src/test/resources']
            }
        }
    }
    
  6. Run the following gradle task from the directory path where build.gradle file is located:

    gradle cucumber

You can help us improve this documentation. Edit this page.