If you are one among those who like Groovy for its simplicity and tight integration with Java (and not for its dynamic capabilities) and wondered how to write Groovy code in a Quarkus application and compile it to native using GraalVM?
I have you covered. You dont have to look anywhere else.
Scope
- groovy code as part of quarkus application
- statically compilable groovy code with no dynamic feature
- compile the final application to native code using graalvm
Code example can be found here.
Steps
- Create a quarkus application as outlined here
- Add your groovy class under src/main/java
- Annotate your groovy class with @groovy.transform.CompileStatic
- create a file called application.properies under src/main/resources folder with the following content.
quarkus.native.additional-build-args=\
--allow-incomplete-classpath, \
--report-unsupported-elements-at-runtime, \
--initialize-at-build-time, \
--initialize-at-run-time=org.codehaus.groovy.control.XStreamUtils\\,groovy.grape.GrapeIvy, \
--no-fallback
Build your native applicaton using,
./mvnw package -Pnative -Dquarkus.native.container-build=true
Voila! You groovy application is compiled to native code.
I would like to use groovy with quarkus for a regular java application.
ReplyDeleteI did the following steps
1. Create a quarkus application as outlined here
2. Add your groovy class under src/main/java
3. Annotate your groovy class with @groovy.transform.CompileStatic
My application worked, only the live reload of the groovy classes didn't.
Will I have a problem? The quarkus documentation doesn't say anything about groovy
Yes, live reload will not work but it should not be a problem in production
ReplyDelete