Skip to content

ParameterType values not resolved when cucumber is run from a fat jar #2146

Closed
@mjbingen

Description

@mjbingen

Describe the bug
When a cucumber project is packaged into a standard fat or uber jar, parameter types are not registered properly and fail during execution. If parameter types are not used or the application is run by adding cucumber jars to the classpath, this works correctly and cucumber can be executed via a fat jar.

To Reproduce
Steps to reproduce the behavior:

  1. Create a step definition that uses an @ParameterType
  2. Package the cucumber application as a far Jar such that all dependencies (classes/resources) are copied into the jar.
  3. Execute the jar (java -jar mycukes.jar)
  4. Observe parameter type registration issue

I have provided a simple example built with gradle here: https://github.com/mjbingen/cucumber-sandbox/tree/fatjar-bug

  1. git clone [email protected]:mjbingen/cucumber-sandbox.git
  2. git checkout fatjar-bug
  3. ./gradlew cucumber (this should work as cucumber + dependencies are simply added to the classpath)
  4. ./gradlew fatJar (fat jar looks good)
  5. java -jar build/libs/run-cukes.jar
  6. See failure:
    SEVERE: Exception while executing pickle
    java.util.concurrent.ExecutionException: io.cucumber.core.exception.CucumberException: Could not create a cucumber expression for 'we have {triple}'.
    It appears you did not register a parameter type.
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at io.cucumber.core.runtime.Runtime.run(Runtime.java:93)
    at io.cucumber.core.cli.Main.run(Main.java:92)
    at io.cucumber.core.cli.Main.main(Main.java:34)
    at com.foo.RunCukes.main(RunCukes.java:23)

Note that the code on the master branch of this repo does not have the ParameterType definition and runs just fine from the fat jar.

Expected behavior
The packaged cucumber application should execute and resolve parameter type definitions whether glue code is added to the classpath or directly embedded into a fat jar executable jar.

Context & Motivation
While packaging a cucumber based app as a "java application" is relatively easy in maven/gradle, it still requires managing all the dependent jars and runtime scripts to set classpaths properly. Sometimes when deploying a test binary to many environments its helpful just to have a fat jar that can be executed.

Your Environment

  • Versions used: 5.0.0 - 6.8.1 (tried various versions in between, but seems like it's existed since ParameterType was introduced)
  • Operating Systems: Mac OS, Linux RedHat 7.7
  • Gradle: 6.2.1 and 5.6.2
  • Java: openjdk version 1.8.0_161; oracle version 1.8.0_131

Additional context
I've tried things like shadow (https://github.com/johnrengelman/shadow) and manual jar creation, but the issue persists. This could be somewhat related to the issue with Spring Jars (#1931) but know they are special in their embedding structure. This is more around the difference between loading jars via classpath vs. embedded in the runnable jar.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions