Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clean or clean build my Maven project in IntelliJ IDEA?

I'm using Apache Maven in my Java project. in NetBeans there are build and clean build icons but there aren't in IntellIJ IDEA. How can I clean or clean build my project in it?

like image 754
Sajad NasiriNezhad Avatar asked Feb 15 '16 12:02

Sajad NasiriNezhad


People also ask

How do you do clean and build in IntelliJ?

To clean up the local working copy, do one of the following: Select the desired file or directory in the Project tool window and choose Subversion | Cleanup from the context menu of the selection. Open the desired file in the editor and choose VCS | Subversion | Cleanup from the main menu.

How do I run a Maven clean test in IntelliJ?

Run testsOpen the Maven tool window. Under the Lifecycle node select test. Note that goals specified in the Maven surefire plugin will be activated at this phase and all tests in a project or in a module will be run.

What is Maven clean build?

Maven clean goal (clean:clean) is bound to the clean phase in the clean lifecycle. Its clean:cleangoal deletes the output of a build by deleting the build directory. Thus, when mvn clean command executes, Maven deletes the build directory.

What is Maven clean install build?

mvn clean install tells Maven to do the clean phase in each module before running the install phase for each module. What this does is clear any compiled files you have, making sure that you're really compiling each module from scratch.


2 Answers

Maven > Lifecycle > clean

Open the Maven Projects panel. Click lower-left corner for pop-up menu if that panel is not already visible.

In that panel, open the Lifecycle item. There you will find clean and install items for you to run.

Screenshot of IntelliJ > Maven > Lifecycle > clean

As commented, you can also invoke this by command-line/console. But if already using IntelliJ, I do not see the point. Just show/hide this pane as you work. I use it countless times a day to hit install to build complete app, and hit clean whenever I suspect not all of the project is up-to-date in the build-results.

Build > Rebuild Project

If you are having weird problems in running the app in development also try the menu item Build > Rebuild Project.

I have asked what is the difference between a Build > Rebuild Project versus doing a Maven clean. But I still do not understand the precise details. So when things seem wonky, I do both to right the ship.

Tips:

  • Restarting IntelliJ may help when behavior seems odd.
  • Keep Intellij updated.
like image 114
Basil Bourque Avatar answered Sep 21 '22 05:09

Basil Bourque


The answer here with the most votes suggests running the clean and install Lifecycle items separately in IntelliJ, which is easy enough and works. But it’s worth mentioning that you can combine these steps (and/or others) by instead creating a new Run/Debug Configuration of type maven and adding the command clean install (or whichever combination of maven lifecycle methods you run on a recurring basis).

Thereafter, running a mvn clean install is as simple as clicking the green button to run that Run/Debug Configuration.

enter image description here

like image 23
Woodchuck Avatar answered Sep 21 '22 05:09

Woodchuck