首页 > 解决方案 > Intellij IDEA Cucumber 插件如果来自依赖项,则看不到步骤定义

问题描述

我在另一个工件中定义了步骤。我从当前项目的 test/java 文件夹中的那个类继承。插件显示警告“未定义的步骤参考”并且无法突出显示或导航到定义。

此处也描述了该问题:
IDEA-104610 Support Cucumber step definitions from other JARs / projects
IDEA-157652 Cucumber intellisense lost when placed stepdefinitions in external library

标签: mavenintellij-ideacucumbercucumber-java

解决方案


Intellij IDEA(我的是 2018.3.6)实际上可以解决和突出显示这些步骤,但前提是您有带有步骤定义的源 jar。因此解决方案是使用 Maven 或其他构建工具下载源代码。

如果您拥有具有测试定义的依赖项,我还想展示如何生成源 jar:

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

如果您还生成单独的测试 jar,那么:

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

推荐阅读