Mongock currently doesn't provide official support for Graalvm. Although it will be officially supported in the next major release, there is a clear(and increasing) demand to have a solution in the short term.
This workaround tries to satisfies this need in the best manner possible.
- The
ChangeUnitsList
: You need to add all the ChangeUnits class you want to run(potentially, ase some of them may be already executed and will be ignored, as usual), as shown
public static final List<Class<?>> changeUnits = Arrays.asList(
ACreateCollection.class,
BInsertDocument.class,
CInsertAnotherDocument.class
);
- The feature
ChangeUnitsRegistrationFeature
. You don't need to do anything, just be aware it exists as you will need it at the image's creation time .setLockGuardEnabled(false)
in the builder..sdkmanrc
provided. If you are not usingsdkman
, please ensure you are using graalvm- Ensure MongoDB is running
- Build jar application with
./gradlew build
- build native image executable with
native-image --no-fallback \
--features=io.mongock.example.graalvm.ChangeUnitsRegistrationFeature \
--initialize-at-build-time=org.slf4j.simple.SimpleLogger,org.slf4j.LoggerFactory,org.slf4j.impl.StaticLoggerBinder \
-jar build/libs/graalvm-example-1.0-SNAPSHOT.jar
- run executable with
./graalvm-example-1.0-SNAPSHOT