-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Remove dependency on java.desktop and other modules #26884
Comments
I guess this is more on the Framework side of things at https://github.com/spring-projects/spring-framework. The Having that said - I'd love to see this in a perfect world, but I doubt it's easy or straightforward, if at all possible. |
We are aware of our rather wide-spread dependencies across the traditional JDK-scoped libraries. Some of those are entirely optional (e.g. JNDI, JMX, RMI and JSR-223 Scripting are only used on demand and do not have to be present at runtime - at least from the core Spring Framework perspective) but the Our only way out is to reimplement the introspection algorithm ourselves and to replace |
Thanks a lot Juergen for sharing the roadmap for 6.0. This will certainly speed up modernization of Java applications with latest JDK releases, as Spring has become a de facto standard of server side development. In the meantime, is there official documentation and/or tooling to help developers produce customized jlink runtimes for 5 and older? Your comment that some modules are optional is key, but I haven't found this in the docs. |
That will help on native side as well. |
Here are some more data points. I found that with a vanilla Spring Boot webflux app
(so no XML modules). If you remove the
You have to add back If Spring 6 could shed I suppose it's an open question for the JDK why The code I used to test: https://github.com/dsyer/sample-docker-microservice UPDATE: you can run without |
Our JNDI support and therefore the |
Just This command will show package-level dependences that you can find out what classes references these modules.
(You can use
|
Thanks @mlchung that's a useful summary and a good example. The point really is that |
Just tried to run Spring without java.desktop and bumped into AnnotationBeanNameGenerator dependency on java.beans.Introspector - just for the sake of using Introspector.decapitalize() in buildDefaultBeanName() :). |
As a workaround, could you provide the "optimal" module configuration for spring with
Am I missing something, or is anything obsolete? |
It depends which features you need at runtime. E.g. see my examples above #26884 (comment) which both have fewer modules than yours. |
@dsyer this is because |
Would the docker build fail if a module is missing that my application would required? |
Pretty sure it’s a runtime error. Why don’t you try it and report back? |
I can report back missing modules result in runtime errors, which is really bad. I discovered it when using a Took me several hours to identify the spot, and fix it by including jdeps Beware that obviously building spring-boot apps with a jdeps minimal jre modules configuration might lead to unpredictable results. |
I am running spring boot 3 (spring framework 6), and still can't run it without java.desktop dependency. I thought the plan was to remove the unnecessary dependencies in spring framework 6. This has not been done yet or the plan was abandoned? |
@sid-hbm The issue is still open and hasn't been done yet. The target is for M6, but that's not a cast-iron guarantee. |
@jhoeller After some additional analysis, I found that our use of The 288 additional classes related to AWT shipped in a native image with our current arrangement is available here which increases the RSS footprint by So strong +1 from me to fix this issue that significantly impacts Spring native application efficiency. |
Maybe in context of this issue, it might be possible for Spring to validate the included I debugged my application for several days due to a |
As per our 6.0 wrap-up discussions and my recent comment on #18079, the module system has not been a priority for 6.0 (for reasons explained in that comment). Not least of it all, we are not shipping module descriptors for jlink usage yet. There would be some value in removing/reducing our dependency on the At the same time, the strategic value of not requiring the presence of the We are considering a reimplementation of the beans introspection algorithm to not have to call the Last but not least, we are going to revisit our module system alignment in the context of Project Leyden which intends to build on module system concepts and tools to some degree. From that perspective, deeper module system alignment remains part of our technology strategy for the Spring Framework 6.x generation. |
That's great to hear, @jhoeller . As we're talking mostly about the modular aspect of this here and the impact on additional classes being loaded in Native, I thought I might give another perspective on this particular sentence. I recently profiled a fairly vanilla Spring-Boot test suite (the project uses Data JPA, Flyway, Web - nothing fancy) and noticed that All these purple blocks show the usage of On the reversed allocation profile for the test suite I get almost 25% of allocations that are only caused by calls to But: in all fairness. In our huge projects I only see 1% impact in production, rather than 13% in the mentioned vanilla project test suite. As tests start several application contexts usually it's not far fetched that the whole beans infrastructure - including Maybe this particular aspect is worth its own ticket, though? |
@dreis2211 We decided to move forward with the Introspector bypass for 6.0 still, in time for Boot 3.0 RC1 next week: #29320 |
That's great news, thanks @jhoeller . Unfortunately, the projects I'm profiling these days are far away from being able to test this easily though. I will report back as soon as I get hold of an internal project here that is willing to experiment with Spring-Boot 3 :) |
@dreis2211 see my comment on #29320 - we could potentially backport an optional variant of this to 5.3.x. Let's continue the conversation over there, we've been hijacking this thread enough already :-) |
Thanks @philwebb for the info. Can't wait the day when spring-boot is completely free from java.desktop and many other unnecessary modules. A simple hello-word spring boot app (just printing a hello) is taking around 170 MB of size for a docker container based on Alpine (the smallest you can use). A similar hello-word in go language would have a very small docker image (with alpine as base). It would be a big celebration when a spring boot docker image becomes small :-) All of the following modules should be removed from spring boot dependencies: java.management, java.security.jgss, java.naming, java.instrument, java.desktop, jdk.unsupported, java.rmi, java.compiler. Just for your info, here is base docker I use currently RUN ["jlink", "--compress=2", "--module-path", Second stage: Copies the custom Java RuntimeImage into a bare alpineFROM alpine:3.20.1 RUN mkdir -p /opt/jdk COPY --from=builder /opt/runtime /opt/jdk |
Spring requires the
java.desktop
module to be present at Java runtimes only so that it can use the classes in the java.beans package.Would be a good start for modernizing Spring apps on a post Java 9+ era of modules if Spring could at least work on slim Java runtimes produced with
jlink
.Other modules to consider adjusting the dependency are
java.naming
,java.xml
,java.sql
,jdk.*
,java.instrument
,java.management
,java.rmi
,java.scripting
.This is not about making Spring compatible with Java SE modules. This is only to allow developers to have smaller Java runtimes created with jlink.
In an ideal world, a Java runtime, created with the following
jlink
command should be sufficient to run a Spring Boot Hello World with the Web dependency:The text was updated successfully, but these errors were encountered: