1

I am working on a Cucumber-BDD Framework where, I added all the required Maven dependencies in my POM.xml But I was not able to import Cucumber.class. I am getting the below error "The import cucumber.api.junit cannot be resolved"

  1. I tried to add manually the JUNIT jar from BuildPath->Libraries
  2. I tried using CTRL+SHIFT+T, but couldnt see the cucumber.api.junit matching item to add the same.
  3. under Maven Dependencies project folder i can see cucumber-junit-4.3.0.jar been added

My POM.xml -

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>BDDFramework</groupId>
  <artifactId>BDDFramework</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>BDDFramework</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm</artifactId>
    <version>4.3.0</version>
    <type>pom</type>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>


<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>4.6.0</version>
</dependency>


<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-core</artifactId>
    <version>4.3.0</version>
</dependency>

    <!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>gherkin</artifactId>
    <version>6.0.17</version>
</dependency>

    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
             <version>3.141.59</version>
         </dependency>   

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>

  </dependencies>
</project>

Expected - import cucumber.api.junit.Cucumber Actual - The import cucumber.api.junit cannot be resolved

Chaitanya Maligi
  • 217
  • 4
  • 7
  • 19

2 Answers2

2

Please remove cucumber-core, cucumber-jvm-deps, gherkin and Junit. They're transitive dependencies and will be provided by your dependencies and after that run mvn clean install and re-import your project in your IDE.(You can add below set of dependency)

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.3.0</version>
    <scope>test</scope>
</dependency>
TheSociety
  • 1,936
  • 2
  • 8
  • 20
  • 3
    Not bad! Just a few corrections `cucumber-picocontainer` is not a transitive depenendecy. `cucumber-jvm` is a transitive dependency (it's a pom) and the version of `junit` is way to old. (`junit` is also a transitive dependency of `cucumber-junit`). Have a look at https://maven.apache.org/plugins/maven-dependency-plugin/tree-mojo.html if you need help to visualize it. – M.P. Korstanje May 01 '19 at 07:00
  • Thank you @mpkorstanje. I would surely look into these and this community has been helping a lot to understand & implement things deeply. – TheSociety May 01 '19 at 07:20
  • @mpkorstanje, Can you please check now as i have updated dependencies in POM.xml. cucumber-core and junit are transitive dependencies of cucumber-junit so those are not included and cucumber-java, datatable are transitive dependencies (few more) of cucumber-picocontainer so removed those as well. – TheSociety May 01 '19 at 07:40
  • I tried adding the cucumber-junit 4.3.0 jar file exclusively in my libraries and it worked. I could not figure out the exact reason as to why cucumber-junit maven dependency didnt work. – Chaitanya Maligi May 01 '19 at 21:05
0

Remove the cucumber.api imports and try with:

import io.cucumber.java.*;

Use the latest version of io.cucumber: 5.4.1

nosequeweaponer
  • 511
  • 10
  • 38