spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 356 forks source link

Runtime dependencies imported in ContextBootstrapInitializer code cause IDE compilation issues #1093

Closed OlgaMaciaszek closed 2 years ago

OlgaMaciaszek commented 3 years ago

Sample that reproduces the issue: discovery-client. After packaging the sample with maven with AOT and running it with the IDE (used IntelliJ for my tests), the IDE was complaining that the aot-generated sources contained imports from missing dependencies, i.e. Google's Gson; adding the dep to pom and refreshing IDE mvn setup fixes the issue, but it's a usability concern.

odrotbohm commented 3 years ago

A similar issue is caused when the projects use ByteBuddy for code transformation as that only considers the compile classpath. I've filed an issue for that to be able to tweak that.

odrotbohm commented 3 years ago

Just for reference, ByteBuddy just released 1.11.19, which contains an option to work against the runtime classpath.

sdeleuze commented 2 years ago

@aclement Could you please check if that's of interest for us?

sdeleuze commented 2 years ago

Spring AOT already considers runtime and not compile classpath for the generation.

What happens here is com.netflix.eureka:eureka-client using runtime dependency for GSON, so as expected it is taken in account.

[INFO] |  +- com.netflix.eureka:eureka-client:jar:1.10.17:compile
[INFO] |  |  +- com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:compile
[INFO] |  |  |  +- com.netflix.netflix-commons:netflix-infix:jar:0.3.0:runtime
[INFO] |  |  |  |  +- commons-jxpath:commons-jxpath:jar:1.3:runtime
[INFO] |  |  |  |  +- joda-time:joda-time:jar:2.3:runtime
[INFO] |  |  |  |  +- org.antlr:antlr-runtime:jar:3.4:runtime
[INFO] |  |  |  |  |  +- org.antlr:stringtemplate:jar:3.2.1:runtime
[INFO] |  |  |  |  |  \- antlr:antlr:jar:2.7.7:runtime
[INFO] |  |  |  |  \- com.google.code.gson:gson:jar:2.8.9:runtime

The IDE automatically attaches the generated code and is using the compile classpath, hence the errors repported: image

After discussing with @snicoll, I think what we would need here is to find a way that IDEs configure the generated code with runtime classpath, or compile + runtime classpath. That may require raising issues on IDE side, so for now I move it to the backlog.

sdeleuze commented 2 years ago

After a discussion with @bclozel, let's change the name of the directory to avoid it to be recognized by IDEA automatically with the wrong classpath, and document how to configure it properly.