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

AOT doesn't work with new micronaut 3.8.5 version #172

Closed
Kartikvk1996 opened this issue Feb 23, 2023 · 9 comments
Closed

AOT doesn't work with new micronaut 3.8.5 version #172

Kartikvk1996 opened this issue Feb 23, 2023 · 9 comments
Assignees
Labels
type: bug Something isn't working

Comments

@Kartikvk1996
Copy link

Kartikvk1996 commented Feb 23, 2023

Expected Behavior

AOT compiler should compile the code and generate optimized jar

Actual Behaviour

Fails with Null pointer exception

[INFO] --- micronaut-maven-plugin:3.5.2:aot-analysis (default-aot-analysis) @ aotTest --- [INFO] Running Micronaut AOT 1.1.1 aot-analysis [INFO] Packaging project [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 2 resources [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:\Users\test\Downloads\aotTest\target\classes [INFO] Executing Micronaut AOT analysis [INFO] Using AOT configuration file: C:\Users\test\Downloads\aotTest\aot-jar.properties 10:38:32.888 [main] INFO i.m.aot.MicronautAotOptimizer - Analysis will be performed with active environments: [] 10:38:33.278 [main] INFO i.m.a.s.s.YamlPropertySourceGenerator - Converting application.yml into Java based configuration 10:38:33.298 [ForkJoinPool.commonPool-worker-7] INFO i.m.a.s.s.YamlPropertySourceGenerator - Converting application.yml into Java based configuration java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at io.micronaut.aot.cli.Main.executeInIsolatedLoader(Main.java:113) at io.micronaut.aot.cli.Main.run(Main.java:87) at picocli.CommandLine.executeUserObject(CommandLine.java:1939) at picocli.CommandLine.access$1300(CommandLine.java:145) at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352) at picocli.CommandLine$RunLast.handle(CommandLine.java:2346) at picocli.CommandLine$RunLast.handle(CommandLine.java:2311) at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179) at picocli.CommandLine.execute(CommandLine.java:2078) at io.micronaut.aot.cli.Main.execute(Main.java:134) at io.micronaut.aot.cli.Main.main(Main.java:138) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at io.micronaut.aot.cli.Main.executeInIsolatedLoader(Main.java:107) ... 10 more Caused by: java.lang.NullPointerException at io.micronaut.aot.MicronautAotOptimizer.compileGeneratedSources(MicronautAotOptimizer.java:123) at io.micronaut.aot.MicronautAotOptimizer.access$200(MicronautAotOptimizer.java:98) at io.micronaut.aot.MicronautAotOptimizer$Runner.execute(MicronautAotOptimizer.java:344) at io.micronaut.aot.MicronautAotOptimizer.execute(MicronautAotOptimizer.java:202) ... 15 more [ERROR] Command execution failed.

Steps To Reproduce

Generate a simple micronaut project using the below command.

mn create-app --build=maven --jdk=8 --lang=java --test=junit --features=micronaut-aot com.example.aottest

or get the same from "Micronaut launch" URL

curl --location --request GET 'https://launch.micronaut.io/create/default/com.example.aotTest?lang=JAVA&build=MAVEN&test=JUNIT&javaVersion=JDK_8&features=micronaut-aot' --output aotTest.zip

Environment Information

  • Windows 10
  • JDK 1.8

Example Application

No response

Version

3.8.5

@sdelamo sdelamo added the type: bug Something isn't working label Feb 23, 2023
@Kartikvk1996
Copy link
Author

Kartikvk1996 commented Feb 28, 2023

@sdelamo @alvarosanchez Any update on this as this is a blocker and we need this feature to speed up application startup time.
I see even with a simple application the plugin fails to generate code.

@melix
Copy link
Collaborator

melix commented Mar 2, 2023

I cannot reproduce the problem. I have tried the CLI you provided, with Micronaut 3.8.5, and executed both ./mvnw mn:run and ./mnvw package, both passed.

I also tried with Gradle and it works too.

@melix
Copy link
Collaborator

melix commented Mar 2, 2023

That said I didn't try under Windows, could be the problem...

@altro3
Copy link
Contributor

altro3 commented Mar 4, 2023

@Kartikvk1996 @melix Can't reproduce it too on Windows 10. All works fine
изображение

@alvarosanchez alvarosanchez closed this as not planned Won't fix, can't repro, duplicate, stale Mar 5, 2023
@Kartikvk1996
Copy link
Author

Kartikvk1996 commented Mar 6, 2023

Trying out different paths resolved the issue for me also.

@melix @altro3 I have a multi-module project with a parent pom, The issue here is all modules use micronaut framework, I want to use AOT for all projects but the challenge is, to use I have to add "micronaut-build-plugin" with the AOT config file path, This generates FAT jar at each modules target location and test cases fail saying "multiple" bean definitions found.

Earlier I had "micronaut-build-plugin" in a module with an "exec" class and here all the other modules' jar files are copied and the FAT jar is generated, but using this approach I am applying AOT to just one module.

Waiting for a proper solution, Can we use the AOT in "compiler-plugin"

@melix
Copy link
Collaborator

melix commented Mar 6, 2023

Multi-project builds are definitely not Maven's selling point. ATM I don't think the Micronaut Maven plugin works well in this context, so I would strongly recommend to use the Gradle plugin instead, the UX should be much better.

@alvarosanchez
Copy link
Member

@Kartikvk1996 I'm unclear about what you want to achieve. Supossing that by "micronaut-build-plugin" you mean the Micronaut Maven Plugin, then it needs to be added only to the module that runs the application (the one that has the main Application class).

Is your question how to use AOT in the other modules?

@Kartikvk1996
Copy link
Author

@alvarosanchez Yes, I want to know how to use AOT for other modules whose pom has only "maven-compiler-plugin" to just compile the class and create a basic jar. Here even if AOT is enabled the plugin doesn't work it needs "micronaut-maven-plugin" to generate AOT classes.

To resolve this I added "micronaut-maven-plugin" to parent pom and now all modules generate FAT jar and it is creating "Multiple bean instances" error when running.

@alvarosanchez
Copy link
Member

I have created micronaut-projects/micronaut-maven-plugin#645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
No open projects
Status: Done
Development

No branches or pull requests

5 participants