Spring在执行之前启动解压缩应用程序



我在通过spring boot jar 运行cucumber测试时收到了这个错误

io.cucumber.core.exception.CompositeCucumberException: There were 2 exceptions:
io.cucumber.core.exception.CucumberException(The resource jar:file:/Users/XTZ/IdeaProjects/eq-data/target/eq-data-0.0.1.jar!/BOOT-INF/lib/xyz-service-starter-2.3.10-1.jar!/com/xyz is located in a nested jar.
This typically happens when trying to run Cucumber inside a Spring Boot Executable Jar.
Cucumber currently doesn't support classpath scanning in nested jars.
Feel free to send a pull request to make this possible!
You can avoid this error by unpacking your application before executing.)

我的问题是如何在执行(unpacking your application before executing(之前进行解压缩?

Spring Boot可执行文件格式描述了Spring如何打包其可执行jar文件。例如:

example.jar
|
+-META-INF
|  +-MANIFEST.MF
+-org
|  +-springframework
|     +-boot
|        +-loader
|           +-<spring boot loader classes>
+-BOOT-INF
+-classes
|  +-com
|    +-example
|       +-project
|          +-StepDefinitions.class
+-lib
+-com.example:utilities:8.0.1.jar
+-com.example:models:4.2.0.jar

默认情况下,Cucumber会扫描整个类路径以查找步骤定义。这包括BOOT-INF/classescom.example:utilities:8.0.1.jarcom.example:models:4.2.0.jar。黄瓜内部不能扫描后两者。

如果步骤定义和功能位于BOOT-INF/classes中,则不必解压缩任何内容。相反,您必须指示Cucumber在特定的包中查找步骤定义。

例如,如果使用io.cucumber.core.cli.Main,则可以通过在cucumber.properties中设置cucumber.glue=com.example.project属性或传递--glue com.example.project来执行此操作。否则,请参阅有关如何配置属性的测试运行程序文档。

如果步骤定义位于其中一个库或两个库中,则必须指示spring-boot-maven-plugin解压缩这些依赖项。此外,您必须指示cucumber只扫描特定库中的包,即:com.example.utilities和/或com.example.models

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<requiresUnpack>
<dependency>
<groupId>com.example</groupId>
<artifactId>utilities</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>models</artifactId>
</dependency>
</requiresUnpack>
</configuration>
</plugin>
</plugins>

还有一个Gradle等价物。

最新更新