Hi im trying to run a test with cucumber, but when i try to run anytest, with IntellJ, show me this error:
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.ArrayList$Itr.next(ArrayList.java:1000)
at java.base/java.util.Collections.max(Collections.java:713)
at io.cucumber.core.feature.FeatureParser.parseResource(FeatureParser.java:46)
at java.base/java.util.function.BiFunction.lambda$andThen$0(BiFunction.java:70)
my POM:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>21.0.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>${cucumber.version}</version>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
</exclusion>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-gherkin-messages</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>${cucumber.version}</version>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>cucumber-java</artifactId>
<groupId>io.cucumber</groupId>
<exclusions>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-gherkin</artifactId>
</exclusion>
<exclusion>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
</exclusion>
</exclusions>
<version>${cucumber.version}</version>
</dependency>
If anyone can help me, i really appreciate it
CodePudding user response:
Your dependencies are inconsistent. You are explicitly excluding transitive dependencies of Cucumber and explicitly including others. You shouldn't do that, Cucumber needs those to function.
I would strongly urge you to invest time in learning how to use Maven (or Gradle) beyond a superficial level. Understanding these tools and the concepts involved can make your life much easier.
For example:
If you want to use Cucumber with JUnit 5 and annotation based step definitions you would declare this minimal set of dependencies in a Maven pom.xml
file.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.9.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-bom</artifactId>
<version>7.10.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit-platform-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<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
command to will list all dependencies and their transitive dependencies.
$ mvn dependency:tree -Dverbose
[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:7.10.1:test
[INFO] | - io.cucumber:cucumber-core:jar:7.10.1:test
[INFO] | | - io.cucumber:cucumber-gherkin:jar:7.10.1:test
[INFO] | | | \- (io.cucumber:cucumber-plugin:jar:7.10.1:test - omitted for duplicate)
[INFO] | | - io.cucumber:cucumber-gherkin-messages:jar:7.10.1:test
[INFO] | | | - io.cucumber:gherkin:jar:25.0.2:test
[INFO] | | | | \- (io.cucumber:messages:jar:19.1.4:test - omitted for duplicate)
[INFO] | | | \- (io.cucumber:cucumber-gherkin:jar:7.10.1:test - omitted for duplicate)
[INFO] | | - io.cucumber:messages:jar:19.1.4:test
[INFO] | | - io.cucumber:tag-expressions:jar:4.1.0:test
[INFO] | | - io.cucumber:cucumber-expressions:jar:16.1.1:test
[INFO] | | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | | - io.cucumber:datatable:jar:7.10.1:test
[INFO] | | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | | - io.cucumber:cucumber-plugin:jar:7.10.1:test
[INFO] | | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | | - io.cucumber:docstring:jar:7.10.1:test
[INFO] | | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | | - io.cucumber:html-formatter:jar:20.2.0:test
[INFO] | | | \- (io.cucumber:messages:jar:19.1.4:test - omitted for duplicate)
[INFO] | | - io.cucumber:ci-environment:jar:9.1.0:test
[INFO] | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] - io.cucumber:cucumber-junit-platform-engine:jar:7.10.1:test
[INFO] | - (io.cucumber:cucumber-core:jar:7.10.1:test - omitted for duplicate)
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.9.1:test
[INFO] | - org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | - org.junit.platform:junit-platform-commons:jar:1.9.1:test
[INFO] | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] - org.junit.platform:junit-platform-suite:jar:1.9.1:test
[INFO] | - org.junit.platform:junit-platform-suite-api:jar:1.9.1:test
[INFO] | | - (org.junit.platform:junit-platform-commons:jar:1.9.1:test - omitted for duplicate)
[INFO] | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | \- org.junit.platform:junit-platform-suite-engine:jar:1.9.1:test
[INFO] | - (org.junit.platform:junit-platform-engine:jar:1.9.1:test - omitted for duplicate)
[INFO] | - (org.junit.platform:junit-platform-suite-api:jar:1.9.1:test - omitted for duplicate)
[INFO] | - (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | \- org.junit.platform:junit-platform-suite-commons:jar:1.9.1:test
[INFO] | - org.junit.platform:junit-platform-launcher:jar:1.9.1:test
[INFO] | | - (org.junit.platform:junit-platform-engine:jar:1.9.1:test - omitted for duplicate)
[INFO] | | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | - (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] | - (org.junit.platform:junit-platform-engine:jar:1.9.1:test - omitted for duplicate)
[INFO] | \- (org.junit.platform:junit-platform-suite-api:jar:1.9.1:test - omitted for duplicate)
[INFO] \- org.junit.jupiter:junit-jupiter:jar:5.9.1:test
[INFO] - org.junit.jupiter:junit-jupiter-api:jar:5.9.1:test
[INFO] | - (org.opentest4j:opentest4j:jar:1.2.0:test - omitted for duplicate)
[INFO] | - (org.junit.platform:junit-platform-commons:jar:1.9.1:test - omitted for duplicate)
[INFO] | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] - org.junit.jupiter:junit-jupiter-params:jar:5.9.1:test
[INFO] | - (org.junit.jupiter:junit-jupiter-api:jar:5.9.1:test - omitted for duplicate)
[INFO] | \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] \- org.junit.jupiter:junit-jupiter-engine:jar:5.9.1:test
[INFO] - (org.junit.platform:junit-platform-engine:jar:1.9.1:test - omitted for duplicate)
[INFO] - (org.junit.jupiter:junit-jupiter-api:jar:5.9.1:test - omitted for duplicate)
[INFO] \- (org.apiguardian:apiguardian-api:jar:1.1.2:test - omitted for duplicate)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.933 s
[INFO] Finished at: 2022-12-28T16:33:23 01:00
[INFO] ------------------------------------------------------------------------
Note: If you see a transitive dependency listed as "omitted for duplicate" and you have also included it in your pom.xml
, this inclusion isn't needed. Maven will download it for you.
Also if you are looking to make a fresh start, you could also use the cucumber-java-skeleton to start with a working project.