Migration guide for Groovy and JavaScript scripts used in the ScriptComponent.
Groovy
Versions
Dovetail | Groovy | Release notes |
---|---|---|
< 4.14.4 | 2.5 | |
4.15.0 | 3.0 | https://groovy-lang.org/releasenotes/groovy-3.0.html |
> 4.16.0 | 4.0 | https://groovy-lang.org/releasenotes/groovy-4.0.html |
Migration
For most Groovy Script nothing needs to change. If a script is not working it's best to check the release notes if your script contains one of the changes listed in the release notes.
JavaScript
Versions
Dovetail | JavaScript | Engine |
---|---|---|
< 4.14.4 | ECMAScript 5.1 | Nashorn |
> 4.15.0 | ECMAScript 2023 | GraalVM |
About the new engine
Until Dovetail 4.14.x, Dovetail was running on Java 8. This Java version came with a JavaScript engine bundled called Nashorn:
https://en.wikipedia.org/wiki/Nashorn_(JavaScript_engine)
For some time Oracle, owner of Java, supported JavaScript by using the Nashorn Engine. Since Java 11 this engine was deprecated citing maintenance challenges by Oracle.
From Dovetail 4.15.x a new engine provided by Oracle is used in the Script component. This engine is called (GraalVM). Oracle says:
“Both Nashorn and GraalVM JavaScript support a similar set of syntax and semantics for Java interoperability. One notable difference is that GraalVM JavaScript takes a secure by default approach, meaning some features need to be explicitly enabled that were available by default on Nashorn. The most important differences relevant for migration are listed here.”
https://www.graalvm.org/latest/reference-manual/js/NashornMigrationGuide/
Scripts need thus be tested if they still work with the new engine.
Predefined variables
Some JavaScript variables were predefined like "request" and "result". Using GraalVM the predefined variables are changed:
Dovetail 4.14.x | Dovetail 4.15.x |
---|---|
context | context |
exchange | exchange |
request | message |
response | body |
properties | properties |
headers | |
body | |
exchangeId | |
result |
Migration
To upgrade it's best to follow following steps:
- Change the predefined variables.
- Remove the "result" variable, the last variable is return by default (result is not need anymore).
- Update script from ECMAScript 5.1 to ECMAScript 2023.
Tip 1: Use a linter
You can test syntax of script online:
Note that it doesn't recognize the predefined variables.
Tip 2: Use ChatGPT
We created a custom GPT that converts a script automatically:
https://chat.openai.com/g/g-geEsZe9iG-javascript-converter-for-dovetail
This (like all ChatGPT's) is not perfect, but can save a bit of time.