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

gradle-build spring-boot devtools hot-reload not working because of hibernate annotation-processor #27744

Open
smoothello opened this issue Oct 31, 2024 · 4 comments

Comments

@smoothello
Copy link

smoothello commented Oct 31, 2024

in the jhipster's build based on gradle, when working on Intellij IDE, the hot-reload functionality provided by spring-boot-devtools fails because of hibernate annotation-processor. During the auto-make/build compilation, the compiler throws error "Problem with Filer: Attempt to recreate a file for type com.example.accessingdatarest.domain.User_" which aborts the re-compilation.
The problem can be reproduced in a much smaller scale project by using the "Accessing JPA Data with REST" spring sample project and then adding spring-boot devtools and hibernate annotation-process to the build-gradle file as shown below:

dependencies {
developmentOnly('org.springframework.boot:spring-boot-devtools')
annotationProcessor('org.hibernate.orm:hibernate-jpamodelgen')

Error message thrown by the compiler is shown below (for Intellij, this shows up in the "auto-build" window):

Information:Errors occurred while compiling module 'accessing-data-rest.main'
Information:javac 21.0.4 was used to compile java sources
Error:java: Problem with Filer: Attempt to recreate a file for type com.example.accessingdatarest.domain.User_

Note1: the project will still automatically restart but code-changes are not recompiled
Note2: if I remove the hibernate annotation-processor (from the spring sample project), the hot-reload works as expected.

Does anyone have a work-around ?

Side-Note1: I'm a bit confused for why no-one else reported the same issue.
Side-Note2: I have the same problem on different OS (windows & ubuntu), different jdks (17 & 21) and different versions of gradle (8.7 & 8.10)

@smoothello smoothello changed the title gradle-build spring-boot-detools hot-reload not working because of hibernate annotation-processor gradle-build spring-boot-devtools hot-reload not working because of hibernate annotation-processor Oct 31, 2024
@smoothello smoothello changed the title gradle-build spring-boot-devtools hot-reload not working because of hibernate annotation-processor gradle-build spring-boot devtools hot-reload not working because of hibernate annotation-processor Oct 31, 2024
@atomfrede
Copy link
Member

Somehow this rings a bell. I thought it was fixed (long ago) but obviously not.

@smoothello
Copy link
Author

smoothello commented Oct 31, 2024

Hi @atomfrede ,
Thanks for your quick feedback !
After playing around further with the smaller spring sample project (described above), I believe that I've managed to make the issue fully repeatable.
The problem seems to be with Intellij auto-make and registry value "compiler.automake.postpone.when.idle.less.than" = 3000 (by default).
If you delete the build folder and then start the app just/right after (within <3secs), that will result in the auto-build happening AFTER the manual build (triggered by the manual start). Hence the compilation linked to the auto-make complains about the generated source-file already existing. After that step, the hot-reload stops working (because after a failed incremental build, gradle tries to switch to a full build ?).
As far as the smaller Spring sample is concerned, just deleting the build folder seems to solve the issue but that doesn't seem to be the case for the bigger jhipster project. Once the compiler error happens, it keeps coming back for each new build.
I haven't found a reliable work-around yet. any suggestion ?

@atomfrede
Copy link
Member

atomfrede commented Nov 5, 2024

Can you try with plain gradle? So two terninals, one running ./gradlew bootRun and the other the build task with continuous flag? (should be ./gradlew compileJava -t). If that works fine, can you check if intellij forwards the build command to gradle? I thought it should be default by now, but I often encounter it not to use it but the internal build/compile which might causes issues.
Edit: Not sure auto make is good idea. Can you disable it and try to trigger build manually?

@smoothello
Copy link
Author

smoothello commented Nov 5, 2024

FYI, I've confirmed that the auto-reload works fine when using gradle directly (1 "bootrun" terminal + 1 "compileJava -t" terminal)
Also, as you mentioned, my IDE which is very recent (2024.2.4 Ultimate edition) uses gradle by default for builds and tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants