'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?



Solution 1:[1]

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

Solution 2:[2]

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.

Solution 3:[3]

Here is a faster way to do that:

in IntelliJ IDEA window hit Ctrl key twice, then a pop-up window appears like this:

enter image description here

there you can enter your command and use recommendation tools, too. including template commands and the list of your previous ones:

enter image description here

Solution 4:[4]

In IntelliJ, go to your Toobar, View>Tools Windows>Maven Projects

From there, you can click Clean to clean the project

Solution 5:[5]

I have the same problem. I found some suggestions but nothing get me to an acceptable solution. Here are some things I found maybe it will help you:

File -> Invalidate caches / restart

or just rebuild the project: Build -> Rebuild project (Shift+F11)
But it's nothing like Clean or Clean and Build from netbeans.

By the way I use intellij-15.

Edit: Finally, Build->Build Artifacts->Build or Rebuild works for me.

Solution 6:[6]

click on maven panel --> select project--> lifecycle --> double click clean.

enter image description here

source: vaadin.com

Solution 7:[7]

So far, the best I can come up with (for a non-Maven project) would be to manually delete the target folder and then do your build. But I'm still looking for a better answer, myself.

I'm building a Maven project, and I discovered if I run the Maven Clean phase from the IntelliJ "Maven Projects" pane, it deletes the target folder. The target folder itself (without subfolders) corresponds to NetBeans' dist folder, and the subfolders in target have corresponding subfolders of the build folder in NetBeans. When you clean and build in NetBeans, the first thing that happens is the build folder and dist folder are deleted, and this corresponds to deleting the target folder in IntelliJ, so that's why I suggest it.

Note that just as you get an error if you try to clean and build in NetBeans while holding open a file that happens to be in the build or dist directory, you will similarly get an error in IntelliJ if you try to execute the Maven Clean phase while a file is open in the target folder - the difference is, if you are doing this in Windows, IntelliJ will half-way delete the folder and there isn't a simple straightforward way to clean up the mess even after you close the program that is holding the file open. Probably if you reboot it will clean up, but who wants to do that? I ended up identifying the culprit process (processes, actually - two copies of explorer.exe) with Sysinternals Process Explorer, killing all instances of explorer (killing only the two culprits didn't seem to work), then starting explorer back up via Task Manager, and everything was fine.

Solution 8:[8]

You can use the terminal to switch to the current project directory and use mvn clean install

Solution 9:[9]

As explained in Jetbrains help there are three ways to execute maven goals in IntelliJ. One simple way to execute clean and install and also save the configuration is to select with CRTL button the goals "clean" and "install" from the maven tab -> Right click in one of the selected -> Modify Run Configuration -> check all the fields -> click OK. Then you can execute this configuration in order to clean and install.

Solution 10:[10]

This way works for the InteliJ IDEA 14 upwards not exceeding InteliJ IDEA 20:

Click Run -> Edit Configurations -> Press + -> Search for "Maven" -> Locate "Command Line" field and enter in following maven commands "clean install" ->  Press OK.

Now click the green button to run that Run/Debug Configuration, this will maven clean install the module/project.

The output of the module if you are to deploy somewhere can be seen in the target directory in the project.

Maven Clean Install refers to clear any compiled files you have, making sure that you're really compiling each module from scratch

Solution 11:[11]

If it's a Maven project:

  1. Go to your project's root folder (where your pom.xml is located)
  2. In address bar of windows explorer type cmd
  3. You should be prompted with cmd window where you should type mvn clean
  4. That will clean your target folder which is getting created after build

Make sure you have your system variables set so mvn commands can work (otherwise you will get "mvn is not recognized as an internal or external command")

This is how it should look: screenshotCMD

Hope this helps.