4

I am fairly new to cucumber-jvm world. Trying to package cucumber spring boot app as Jar. app runs fine from Eclipse. But when I package as executable jar it fails with Exception :

Exception in Main Thread, No backend Module found. Make sure that you have backend module on CLASSPATH. Kindly help. Thank you.

shah
  • 77
  • 1
  • 5
  • DO you have jars like cucumber-java, cucumber-core etc etc in the classpath? This error is thrown when implementation of Backend.java is not found in cucumber.runtime package. Refer to line 56 at- https://github.com/cucumber/cucumber-jvm/blob/v2.4.0/core/src/main/java/cucumber/runtime/Runtime.java – Grasshopper May 10 '18 at 07:36
  • Yes I do have cucumber-java, cucumber-core 1.2.5 on classpath. And I can see the JavaBackend class in cucumber.runtime package. – shah May 10 '18 at 14:41

2 Answers2

2

From: https://github.com/cucumber/cucumber-jvm/issues/1320

SpringBoot uses a nested jar structure that requires the use of ApplicationContext.getResources to access it transparently. You'll have to create your own instance of the Cucumber runtime and provide it a class loader and resource loader that use the ApplicationContext.

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
0

Using Gradle, place the Cucumber artifacts (ie features, step implementations, etc) into a subproject, eg my-cucumber-tests, separate from the Spring Boot app.

Then in the Spring Boot app's build.gradle, add:

bootJar {
  // make backend, features, and steps available to Cucumber at runtime
  requiresUnpack '**/my-cucumber-tests-*.jar', '**/cucumber-java-*.jar'
}
Noel Yap
  • 18,822
  • 21
  • 92
  • 144
  • Could you elaborate? What exactly goes into this subproject and what stays at the "main" project? – Saita Sep 19 '19 at 12:42
  • The `my-cucumber-tests` subproject contains the Cucumber features, step implementations, etc. The `main` project, ideally (although we haven't yet achieved the ideal) contains the `main` function and everything else that's server-related. Ideally there's a separation of concerns: one subproject is server-related code and the other subproject is Cucumber-related code. – Noel Yap Sep 20 '19 at 15:40