Reputation: 301
I am running into problems when using IntelliJ for Spring development. At first, the IntelliJ build
command works fine and picks up changes I make to the source code. At some point, this stops working and I can only compile my sources through maven, as the build
or rebuild project
commands seem to do nothing anymore.
I am confused, as it works as desired at the start but then stops working at some point.
Steps to recreate:
Create a new Spring project using Spring Initializr:
curl https://start.spring.io/starter.zip -d type=maven-project -d javaVersion=11 -o demo.zip && unzip demo.zip
Start IntelliJ from the command line in that folder, this will auto-import the project: idea64 .
Write a log message in the main class and run the project using Run->Run 'DemoApplication'
. This compiles the sources to the target
folder and starts up the project. You should see the log message
Alter the log message, run again and the changes should be visible (so far so good)
Now re-compile the sources via maven command mvn compile
and restart IntelliJ
From now on, running build
or rebuild project
within IntelliJ will not pick up any changes I make to any of my source files. In fact both commands don't seem to do anything at all. I have to compile via maven in order to properly compile my sources
I tried a few things to overcome this problem, but without success:
project settings
for Project Compiler Output
and set it to <project-folder>/target
project settings/modules
for output path
and test output path
and put in the path as aboveReimport All Maven Projects
.idea
folder within the project folder. This seems to work, but is very inconvenient and surely no intended behavior. Also it breaks again if I recreate the steps detailed above.Is anyone experiencing similar problems and/or has a solution?
Upvotes: 5
Views: 9554
Reputation: 14003
I'm not 100% sure if I understood the entire problem. For me saving the files via Ctrl+S
and then simply stopping/restarting the server didn't make the changes appear in the webapp until I opened the Project Settings -> Artifacts -> *.war/ear: exploded
-> check "Include in project build".
Before that, I had to manually execute clean + package in the Maven tab, which is slow.
Upvotes: 0
Reputation: 2786
Sounds like do don't want Intellij's default build. You want Intellij to forward the build command to mvn. I assume this because you do not mention this step in your question.
Here's a screenshot that shows how to enable it:
More detail is available in the Intellij documentation https://www.jetbrains.com/help/idea/delegate-build-and-run-actions-to-maven.html#delegate_run_action
Upvotes: 7
Reputation: 301
So for anyone running into the problems I described above:
Apparently deleting the .idea
folder and restarting IntelliJ does indeed do the trick. The folder is recreated on restart and afterwards I'm able to switch between compiling within IntelliJ using run
, build
or rebuild project
and compiling through maven goals (mvn compile
, mvn test
, mvn surefire:test
, ...). This persists through restarts of IntelliJ such that I don't have to repeat this everytime I open a project.
I still don't know why this behavior happens, but it's a solution I'm happy to work with as long as I only have to do it every now and then for a project.
Upvotes: 10