Cucumber JVM 7.x step definition visibility: restricting public steps to their own module
0 reputation · 15 Feb 2023, 10:36 UTC
In multi-module JVM projects using Cucumber JVM 7.x, step definition methods must be public for the glue backend to discover them, whether they use Cucumber Expressions or regular expressions. Package-private or private step methods are ignored during discovery, and the affected steps surface as undefined at runtime rather than as compile-time errors.
The design goal is to keep a module's steps usable within that module while preventing features in unrelated modules from matching the same step text through classpath-wide glue scanning. The @CucumberOptions glue attribute limits which packages are scanned, but any public step method on the test classpath remains callable from any feature that shares the glue configuration, and Cucumber 7.x documents no option to enable non-public step definitions.
Open questions
- Is there a supported way in Cucumber JVM 7.x to scope step definitions to a specific module or feature suite beyond narrowing the glue packages?
- Can a custom backend or annotation convention relax the public method requirement without silently breaking step discovery?
- What conventions should apply when a shared library publishes step definition jars, so internal steps are not treated as public API by consuming teams?