Skip to content

Exclude spring-boot-devtools from AOT processing in Maven #46533

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
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

academey
Copy link

This PR ensures that spring-boot-devtools is excluded from AOT processing when building native images with Maven, matching the existing behavior in Gradle.

Problem:
When building native images with Maven, spring-boot-devtools remains on the classpath during AOT processing. This causes issues because devtools uses features incompatible with native images (like class proxies). In contrast, Gradle automatically excludes devtools through its developmentOnly configuration.

Solution:

  • Applied the existing DEVTOOLS_EXCLUDE_FILTER to the classpath used during AOT processing in both ProcessAotMojo and ProcessTestAotMojo
  • This ensures devtools is automatically excluded without requiring any user configuration

Testing:

  • Added integration tests that verify devtools is properly excluded during both main and test AOT processing
  • The tests include projects with devtools as a dependency and confirm that AOT processing completes successfully

Fixes #32853

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 24, 2025
@snicoll
Copy link
Member

snicoll commented Aug 11, 2025

@academey that's not strictly what we have in mind. Yes, remove devtools from the classpath that AOT considers to process the application, but also from the native image. This PR does the former, but not the latter. Would you be willing to amend it? There is some context in the linked issue.

@snicoll snicoll added the status: waiting-for-feedback We need additional information before we can continue label Aug 11, 2025
@academey
Copy link
Author

@snicoll Thank you for the feedback. After investigating further, I understand the issue better now.

You're right. My current changes only exclude devtools from AOT processing but not from the native image itself. The issue is that while process-aot correctly excludes devtools, the native-maven-plugin still uses Maven's full classpath which includes devtools.

From my analysis, I see a few potential approaches

  1. Configure exclusion in the native profile: We could add configuration to exclude devtools when the native profile is active, similar to how Gradle's developmentOnly configuration works.

  2. Modify the parent POM's native profile: Add devtools exclusion to the native-maven-plugin configuration in spring-boot-starter-parent.

  3. Use Maven's dependency scope: Leverage Maven's dependency management to ensure devtools doesn't appear in the runtime classpath for native builds.

Could you provide guidance on which approach would be most consistent with Spring Boot's design? I'm happy to implement the full solution once we agree on the direction.

For reference, I believe the issue occurs because native-maven-plugin uses the raw classpath (as mentioned in the AOT docs), and devtools remains in that classpath even though it's excluded from AOT processing.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 11, 2025
@snicoll
Copy link
Member

snicoll commented Aug 11, 2025

I don't see the difference between 1 and 2. 2 is what I had in mind (at least trying) but it looks identical to 1.

@snicoll snicoll added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Aug 11, 2025
@academey
Copy link
Author

@snicoll You're right approaches 1 and 2 are the same. I was overthinking it

I'll implement the solution by modifying the native profile in spring-boot-starter-parent to exclude devtools. This approach makes sense as it

  • Centralizes the configuration
  • Ensures consistent behavior across all projects using the parent POM
  • Aligns with how we handle other native image configurations

I'll update the PR to include these changes. Thanks for the clarification

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 11, 2025
@academey academey force-pushed the gh-32853-exclude-devtools-native-maven branch from 397d692 to e4af14b Compare August 11, 2025 14:00
… Maven

Previously, spring-boot-devtools was only excluded from native images
built with Gradle but not with Maven. This inconsistency meant that
Maven builds would include devtools in the AOT processing classpath
and in the native image, causing build failures.

This commit:
- Applies DEVTOOLS_EXCLUDE_FILTER to the classpath during both main
  and test AOT processing in Maven plugin
- Adds exclusions for devtools and docker-compose in the
  native-maven-plugin configuration within spring-boot-starter-parent
- Ensures devtools is completely excluded from native images, not just
  from AOT processing

The exclusion happens automatically without requiring any user
configuration, ensuring that devtools is properly excluded from
native images while maintaining its functionality during development.

Fixes spring-projectsgh-32853

Signed-off-by: academey <[email protected]>
@academey academey force-pushed the gh-32853-exclude-devtools-native-maven branch from e4af14b to d34f176 Compare August 11, 2025 14:07
@academey
Copy link
Author

academey commented Aug 11, 2025

@snicoll I've updated the PR

The changes now include

  1. AOT processing exclusion. Applied DEVTOOLS_EXCLUDE_FILTER in both ProcessAotMojo and ProcessTestAotMojo
  2. Native image exclusion. Added exclusions for both spring-boot-devtools and spring-boot-docker-compose in the native-maven-plugin configuration within spring-boot-starter-parent

This ensures devtools is completely excluded from native images built with Maven, matching the Gradle behavior. The exclusions are applied automatically without requiring any user configuration.

Please let me know if this approach looks good or if you'd like any adjustments!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exclude spring-boot-devtools from AOT processing and native images built with Maven
3 participants