Im trying to run my springboot project with gradle with the gradle bootRun command. However I get the error below :
* Executing task: gradle: bootRun
Task :compileJava FAILED
1 actionable task: 1 executed
<-------------> 0% WAITING
IDLE
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
java.io.IOException: Unable to delete directory 'C:\Users\victo\OneDrive\Desktop\expense_tracker\expense_tracker_backend\build\classes\java\main'
Failed to delete some children. This might happen because a process has files open or has its working directory set in the target directory.
- C:\Users\victo\OneDrive\Desktop\expense_tracker\expense_tracker_backend\build\classes\java\main\com\expense_tracker_backend
- C:\Users\victo\OneDrive\Desktop\expense_tracker\expense_tracker_backend\build\classes\java\main\com
However I dont think I have been running anything else. Im new to springboot so any help will be appreciated Im using gradle 8.12.1 and using java openjdk version "21" 2023-09-19
Ive tried closing file explorer, closing any other open terminals, paused OneDrive saving, closed any java stuff running with taskkill /F /IM java.exe
, and I have also made sure to stop any gradle daemons running. I expected this to make sure that no other processes would have files open. I have been running gradle runBoo
t through the vs code gradle extension. At this point I dont know what else might be causing this issue. If you need any more information let me know and Ill do my best to answer in a timely fashion
So the issue was not with antivirus, IDE, terminal or file permissions. It had to do with gradle's daemon. It might have to with the fact that the deamon gradle had a lock on a file in the build directory. This might have been caused because I changed the name of some folders in my project. Below are the steps I took to fix this.
1: Delete the build folder (not sure if this is necessary but just in case I included it here)
2: run the following command in your root directory: ./gradlew --no-daemon clean
(This should clean out your build directory if you have not done the 1st step.)
3: then run the following command to build ./gradlew build --rerun-tasks -x test
--rerun-tasks make sure that no task is skipped and -x test makes sure that you skip the test task which was useful in my situation as I did not have test.
4: then you can run the following to start spring boot. ./gradlew bootRun
.
After this using the gradle daemon should work normally.