Skip to content

Exclude spring-boot-devtools from AOT processing and native images built with Maven #32853

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

Open
wilkinsona opened this issue Oct 24, 2022 · 15 comments
Labels
type: task A general task
Milestone

Comments

@wilkinsona
Copy link
Member

We've had a couple of issues in this area already:

The first was Maven-specific as, when using Gradle, the developmentOnly configuration meant that DevTools wasn't on the classpath when performing AOT processing with Gradle. It was fixed by disabling DevTools during AOT processing. The second was Gradle-specific as developmentOnly dependencies were only the classpath of the native image but they hadn't been processed ahead-of-time so a failure occurred when the native image was started.

With the first fix in place, a Maven-built native image will include DevTools but it'll be disabled. As such, its inclusion is benign other than bloating the image. That bloat is only ~145KB as far as I can tell, but we should eliminate it if we can by removing DevTools from the classpath.

@wilkinsona wilkinsona added the type: task A general task label Oct 24, 2022
@wilkinsona wilkinsona added this to the 3.0.x milestone Oct 24, 2022
@sdeleuze
Copy link
Contributor

sdeleuze commented Jan 2, 2023

Based on my test with Spring Boot 3.0.1, the behavior I see is that creating a project on https://start.spring.io/ with native and Devtools works with Gradle but is broken with Maven at runtime with this exception:
https://gist.github.com/sdeleuze/4b3eda4fedfb98eef820cc8888af9c26

Maybe fixing this issue would fix that error and remove the bloat at the same time?

@DuncanCasteleyn
Copy link

DuncanCasteleyn commented Jan 2, 2023

I have encountered the same issue with maven when using spring-boot:build-image the native image will work, but when using native:compile running the executable will fail due to devtools even though it was configured as an optional dependency.
Removing devtools as dependecy from the pom.xml resolves the problem.

@mhalbritter
Copy link
Contributor

mhalbritter commented Jan 10, 2023

We can exclude the devtools in org.springframework.boot.maven.ProcessAotMojo#getClassPath with this:

		Exclude exclude = new Exclude();
		exclude.setGroupId("org.springframework.boot");
		exclude.setArtifactId("spring-boot-devtools");
		return getClassPath(directories, new ExcludeTestScopeArtifactFilter(), new ExcludeFilter(exclude));

But this only excludes the devtools from the AOT processing phase, not from the inclusion in the native image and it will still fail when the native binary runs.

We don't supply native-image with the classpath, this is done in the native-maven-plugin itself here: https://github.com/graalvm/native-build-tools/blob/c4762a78f9c80b653ff4e3be8f3bb3fc6dd60d90/native-maven-plugin/src/main/java/org/graalvm/buildtools/maven/AbstractNativeImageMojo.java#L323

One can override the whole classpath used for native compilation. We don't do that in our starter-parent, we only point native-image to our classes (application classes and AOT generated classes) and let native image itself figure out the classpath.

I think the way forward would be to add something to native-maven-plugin which enables automatic population of the classpath (which is already implemented) but with the option of excluding dependencies. We could then add the exclusion of the devtools in our starter-parent.

What do you think?

@wilkinsona
Copy link
Member Author

That sounds like a good long-term solution although I wonder if they'd agree to the extra complexity for something that is probably quite unusual. In the shorter term, I think we should consider updating DevToolsEnablementDeducer to disable DevTools in a native image. This will still be useful in the longer term even with the proposed changes to the native Maven plugin if the dependency ends up in the native image anyway, for example because someone isn't using spring-boot-starter-parent.

@mhalbritter
Copy link
Contributor

mhalbritter commented Jan 11, 2023

Projects with devtools included are now working again with Maven. The DevToolsPropertyDefaultsPostProcessor will now back off in a native image. The code is still included in the native image, but it won't run.

The problem with excluding devtools from the classpath when building a native image still stands.

@oliveryasuna
Copy link

oliveryasuna commented Jun 21, 2023

+1. Also experiencing this issue.

@wilkinsona
Copy link
Member Author

@oliveryasuna what problem are you experiencing? AFAIK, there are no longer any problems with Devtools in a native image as it will be disabled.

@sdeleuze
Copy link
Contributor

Could be #35853, this currently breaks Petlinic with Maven when org.springframework.boot:spring-boot-devtools is added.

@wilkinsona
Copy link
Member Author

Thanks, @sdeleuze. I'd forgotten about that one. @oliveryasuna, are you using Spring Boot 3.1.0?

@GregaVrbancic
Copy link

Hi @wilkinsona, I am experiencing the same issue using Spring Boot 3.1.0. When spring-boot-devtools are included in pom.xml, the application throws the following exception at startup:

        at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:651)
        at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:675)
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
        at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
        at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:462)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:458)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:274)
        at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:253)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1305)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1294)
        at si.um.feri.isl.dataHub.DataHub.main(DataHub.java:26)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.devtools.restart.RestartScopeInitializer
        at [email protected]/java.lang.Class.forName(DynamicHub.java:1132)
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:224)
        ... 9 more```

However, when I remove spring-boot-devtools dependency everything works fine.

@oliveryasuna
Copy link

My workaround was to make spring-boot-devtools scope provided in my native profile.

@wilkinsona
Copy link
Member Author

wilkinsona commented Jun 21, 2023

Thanks, both. This should bee fixed in tomorrow's 3.1.1 release through #35853.

@oliveryasuna
Copy link

oliveryasuna commented Jun 21, 2023

@wilkinsona Yes, I am using 3.1.0. AOT includes Devtools.

@philwebb philwebb modified the milestones: 3.0.x, 3.1.x Nov 8, 2023
@wilkinsona wilkinsona modified the milestones: 3.1.x, 3.2.x May 20, 2024
@snicoll
Copy link
Member

snicoll commented Jul 29, 2024

To hopefully get the ball rolling again, I've submitted a RFE for the native image Maven plugin, see graalvm/native-build-tools#612

@mhalbritter mhalbritter added the for: team-meeting An issue we'd like to discuss as a team to make progress label Sep 11, 2024
@wilkinsona wilkinsona removed the for: team-meeting An issue we'd like to discuss as a team to make progress label Oct 14, 2024
@wilkinsona wilkinsona added the status: blocked An issue that's blocked on an external project change label Nov 8, 2024
@wilkinsona wilkinsona modified the milestones: 3.2.x, 3.x Nov 8, 2024
@mhalbritter
Copy link
Contributor

graalvm/native-build-tools#612 has been resolved and should be released in NBT 0.10.6.

@mhalbritter mhalbritter removed the status: blocked An issue that's blocked on an external project change label Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

9 participants