There are various issues with this (See https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader) but also if you are programmatically using cucumber, this means any static variables before you call off to to the test framework can be lost because it loses all the child class loaders. Note this is more of a problem for groovy and runtime compilation because classloaders are more dynamic as needed.
Instead should switch to a form of getClass().getClassLoader() to preserve the child class loaders.
The work around for anyone else is to use Thread.currentThread().setContextClassLoader(getClass().getClassLoader()) before calling off to cucumber. More difficult than it sounds as you actually have to re-write part of the cucumber API and create your own ParentRunner just to wrap the calls in this.
Cucumber groovy makes use of the context class loader.
https://github.com/cucumber/cucumber-jvm-groovy/blob/0d4c4cdfe64d3c897938c454f9b38c6b721125a2/groovy/src/main/java/io/cucumber/groovy/GroovyBackend.java#L58
return new GroovyShell(Thread.currentThread().getContextClassLoader(), new Binding(), compilerConfig);
There are various issues with this (See https://stackoverflow.com/questions/1771679/difference-between-threads-context-class-loader-and-normal-classloader) but also if you are programmatically using cucumber, this means any static variables before you call off to to the test framework can be lost because it loses all the child class loaders. Note this is more of a problem for groovy and runtime compilation because classloaders are more dynamic as needed.
Instead should switch to a form of
getClass().getClassLoader()
to preserve the child class loaders.The work around for anyone else is to use
Thread.currentThread().setContextClassLoader(getClass().getClassLoader())
before calling off to cucumber. More difficult than it sounds as you actually have to re-write part of the cucumber API and create your own ParentRunner just to wrap the calls in this.