Intellij IDEA Cucumber 插件看不到来自依赖项的步骤定义

Intellij IDEA Cucumber plugin doesn't see step definitions if they come from dependency

我在另一个工件中定义了步骤。我从当前项目的 test/java 文件夹中的那个 class 继承。插件显示警告 "Undefined step reference" 并且无法突出显示或导航到定义。

这里也描述了这个问题:
IDEA-104610 支持来自其他 JAR/项目的 Cucumber 步骤定义
IDEA-157652 在外部库中放置步骤定义时 Cucumber 智能感知丢失

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>