Vikas Thange
Vikas Thange

Reputation: 250

How to link StepDefination classes from Classpath (jar) in Cucumber IntelliJ Plugin

I would like to use existing step definition classes coming from maven jar dependency.

My cucumber tests works if ran from Runner Class (with glue to packages) & mvn CLI. But the problem is with IntelliJ Cucumber plugin for the steps which are coming from jar. In feature file steps that I am using from the jar are shown as "Undefined step reference:...". I am not even able to run directly from feature file.

Is there a way I can configure cucumber plugin to use stepdefinations from classloader/jar?

Upvotes: 0

Views: 945

Answers (2)

Sheeran D
Sheeran D

Reputation: 61

Updating Intellij from version 2019.3 to 2022.2 solved the issue without changing anything else. My project is in Java 8

Upvotes: 0

Vikas Thange
Vikas Thange

Reputation: 250

Posting the solution worked for Me:

  • Use IntelliJ 2020.1 +
  • In cucumber run configuration : select jar manifest for classpath
  • Deploy the Jar with source jar as well to Nexus as below

You can simple do this by adding maven-source-plugin plugin to your build

    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.2.0</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    </build>

  • In other project add dependency and confirm source is downloaded from repo

File -> Project Structure -> Libraries -> Select the Artifact -> Sources , Make sure it's not in red.

  • Update IntelliJ to use latest version, for me IntelliJ version 2019 did not work but 2020.1 was able to find the step definitions.

PS: I use Java8 with Lambda exp and I can confirm it works.

Upvotes: 0

Related Questions