JSR223 Sampler have a statement that Groovy is implementing Compilable interface different than other scripting languages and therefore is recommended
You need to get ScriptEngine instance instead of ScriptEngineFactory
final ScriptEngine engine = engineFactory.getScriptEngine();
if (engine instanceof Compilable) {
...
Why all Compilable? Because these script engines may be compilable in the future. But currently not support, so they all implement this interface.
You may try to compile the empty string:
if (engine instanceof Compilable) {
try {
((Compilable) engine).compile("");
} catch (Error e) {
System.out.println(engineName + " Script compilation is not supported.");
} catch (ScriptException e) {
e.printStackTrace();
}
System.out.println(engineName + " Script compilation is supported.");
} else {
System.out.println(engineName + " Script compilation is not supported.");
}