Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongock build AOT fail in Spring Boot 3.0.1 #597

Open
nhandev552 opened this issue Jan 8, 2023 · 16 comments
Open

Mongock build AOT fail in Spring Boot 3.0.1 #597

nhandev552 opened this issue Jan 8, 2023 · 16 comments
Assignees

Comments

@nhandev552
Copy link

nhandev552 commented Jan 8, 2023

Description

Mongock build AOT fail in Spring Boot 3.0.1

Mongock

        <groupId>io.mongock</groupId>
        <artifactId>mongock-springboot-v3</artifactId>
        <version>5.2.1</version>
    </dependency>
    <dependency>
        <groupId>io.mongock</groupId>
        <artifactId>mongodb-springdata-v4-driver</artifactId>
        <version>5.2.1</version>
    </dependency>

Environment

  • Spring boot 3.0.1, graalvm-ce-17(version 17.0.5)

Steps to Reproduce

  1. Run cli mvn spring-boot:process-aot

Behaviour

Actual behavior:

Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it: io.mongock.driver.mongodb.springdata.v4.config.MongoDBConfiguration$WriteConcernLevel

Link to repository using Mongock

[While not mandatory, accessing to the real code that uses Mongock, would help to solve the issue]

Additional context

Log

. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' |
| .__|| ||| |_, | / / / /
=========|
|==============|/=////
:: Spring Boot :: (v3.0.1)

11:59:21.451 [main] INFO vn.dolenglish.exercise.Application - No active profile set, falling back to 1 default profile: "default"
11:59:22.035 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
11:59:22.068 [main] INFO o.s.d.r.c.RepositoryConfigurationDelegate - Finished Spring Data repository scanning in 30 ms. Found 8 MongoDB repository interfaces.
11:59:22.358 [main] INFO o.s.cloud.context.scope.GenericScope - BeanFactory id=a4ba64fd-1372-3075-bf0e-03f8404705bc

Constructor binding in a native image requires compilation with -parameters but the following classes were compiled without it:
io.mongock.driver.mongodb.springdata.v4.config.MongoDBConfiguration$WriteConcernLevel
at org.springframework.boot.context.properties.bind.BindableRuntimeHintsRegistrar.registerHints(BindableRuntimeHintsRegistrar.java:87)
at org.springframework.boot.context.properties.ConfigurationPropertiesBeanFactoryInitializationAotProcessor$ConfigurationPropertiesReflectionHintsContribution.applyTo(ConfigurationPropertiesBeanFactoryInitializationAotProcessor.java:70)
at org.springframework.context.aot.BeanFactoryInitializationAotContributions.applyTo(BeanFactoryInitializationAotContributions.java:78)
at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:58)
at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:76)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.577 s

@nhandev552 nhandev552 changed the title Spring boot AOT build fail with Spring Boot 3.0.1 Mongock build AOT fail in Spring Boot 3.0.1 Jan 8, 2023
@dieppa
Copy link
Member

dieppa commented Jan 11, 2023

Hello, we need to take a look to this in detail, but I bet is related to the conflict between Mongock using reflection and Graal Naive AOT compilation.

Although that's something will support in the next version, Mongock currently doesn't provide explicit support for AOT.

Anyway, we'll keep you updated as this is something that we need to address soon.

@dieppa
Copy link
Member

dieppa commented Jan 11, 2023

@nhandev552 if you can build a small project to which we can access via github and try ourselves would help a lot. Thanks

@dieppa
Copy link
Member

dieppa commented Jan 18, 2023

Hello @nhandev552 , could you provide that, so we can help you faster?

@nhandev552
Copy link
Author

Hi, @dieppa thanks for supporting.

The simple project to reproduce: https://github.com/nhandev552/mongck-with-aot.

I worked around by clone mongodb-springdata-v4-driver source code and adding @NestedConfigurationProperty on the field io.mongock.driver.mongodb.springdata.v4.config.MongoDBConfiguration.WriteConcernLevel, building AOT works well

@dieppa
Copy link
Member

dieppa commented Jan 18, 2023

Thanks @nhandev552, for the project. We'll let you know soon.

Anyway, If you thing that it's a workaround that is valiable for now, you may want to create a PR and we can take a look.

Thanks!!

@Rocker93
Copy link

I can confirm the issue. The mentioned fix is part of the solution. Second issue is that MongockCommunityProperties doesn't expose mongock.properties resource for native processing. As a workaround it is possible to add it into app resources and expose via native hints.

@Rocker93
Copy link

Even after the changes proposed, I still have issues with Mongock. Mongock works fine when the same app runs on JVM, unfortunately, the GraalVM build has the following issues. For some reason MongoSync4ChangeEntryRepository#getEntriesLog doesn't return any result. I've tried registering native hints for MongoDB Document, FindIterable, but it didn't help. The other issue is that MigrateExecutorBase#fetchAndPrepareChangeLogs doesn't return any result, even though I've registered all changelogs in native hints as well.

@mathieuales
Copy link

Hi !
Any news on this subject?
I'm facing same same issue
I added mongock.properties to hints resources but next problem seems related to org.reflections:

org.reflections.ReflectionsException: could not create Vfs.Dir from url, no matching UrlType was found [resource:/] either use fromURL(final URL url, final List<UrlType> urlTypes) or use the static setDefaultURLTypes(final List urlTypes) or addDefaultURLTypes(UrlType urlType) with your specialized UrlType.
at org.reflections.vfs.Vfs.fromURL(Vfs.java:113) at org.reflections.vfs.Vfs.fromURL(Vfs.java:95) at org.reflections.Reflections.lambda$scan$2(Reflections.java:176) at java.base@17.0.6/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) at java.base@17.0.6/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1707) at java.base@17.0.6/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) at java.base@17.0.6/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290) at java.base@17.0.6/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:754) at java.base@17.0.6/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) at java.base@17.0.6/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:686) at java.base@17.0.6/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159) at java.base@17.0.6/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173) at java.base@17.0.6/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) at java.base@17.0.6/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) at java.base@17.0.6/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:765) at org.reflections.Reflections.scan(Reflections.java:173) at org.reflections.Reflections.<init>(Reflections.java:126) at org.reflections.Reflections.<init>(Reflections.java:159) at io.mongock.runner.core.executor.changelog.ChangeLogServiceBase.mergeChangeLogClassesAndPackages(ChangeLogServiceBase.java:160) at io.mongock.runner.core.executor.changelog.ChangeLogServiceBase.fetchChangeLogs(ChangeLogServiceBase.java:138) at io.mongock.runner.core.executor.operation.migrate.MigrateExecutorBase.fetchAndPrepareChangeLogs(MigrateExecutorBase.java:77) at io.mongock.runner.core.executor.operation.migrate.MigrateExecutorBase.executeMigration(MigrateExecutorBase.java:47) at io.mongock.runner.core.executor.operation.migrate.MigrateExecutorBase.executeMigration(MigrateExecutorBase.java:18) at io.mongock.runner.core.executor.MongockRunnerImpl.execute(MongockRunnerImpl.java:57)

@dieppa
Copy link
Member

dieppa commented Oct 2, 2023

Hello, we are working on a workaround for this. We expect to have it at the end of this week, beginning of next week.

@dieppa
Copy link
Member

dieppa commented Oct 12, 2023

Sorry, we under estimate it, not because it's complex, we know what we need to do, but because we have a lot in our plates. I will notify you when it is ready 😃

@dieppa
Copy link
Member

dieppa commented Oct 25, 2023

We wanted to provide official support in the next major release. However, this is getting more and more attention and we won't be able to contain it much longer. So we have decided to provide a decent workaround to allow you guys to carry on working and add it in the next release as part of the core.

We did a POC to check the work needed and we are confident in releasing the workaround soon.

@dieppa
Copy link
Member

dieppa commented Nov 6, 2023

Hello @mathieuales , @Rocker93 and @nhandev552 , sorry for the delay.

As mentioned, we'll provide official support with a proper solution in the next major release, however, as there is a clear demand for this, we have release a workaround with the expectation you can carry on working until the official GraaVM support is released.

We have create an example that you can pull form this repo.

Please let us know if you find anything or you need some help.

Thanks for the patience.

@mathieuales
Copy link

Thanks for example, i'll try this asap

@rfelgent
Copy link

rfelgent commented Jan 11, 2024

hello,

what is the current state @dieppa ? Is there official support by mongock library or do I have to use that work around?

@dieppa
Copy link
Member

dieppa commented Jan 13, 2024

In the next major release we'll provide official support, but it won't be in this first quarter. Probably, starting Q2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants