Use Maven to Build and run your project in IntelliJ IDEA

Writen by: David Vlijmincx


The problem is that I have two development environments on my laptop, one inside Windows and one inside Linux using WSL2. Which normally works great except when it does not. My issues came from the wrong Maven being used and IntelliJ not playing nice WSL2.

If you are using WSL2 and your maven project won't find imports, run, or find the correct settings, the following might help.

Before you start this, make sure you have the correct Maven setup inside the setting of IntelliJ. You can check this by going to File -> Settings -> Build, Execution, Deployment -> Build tools -> Maven. Make sure you select the correct Maven home path.

Delegate run and build to Maven

To force IntelliJ to use Maven for Run and Build, you have to select a single checkbox, which is quite well hidden inside the menu options.

You can find this setting under: File -> Settings -> Build, Execution, Deployment -> Build tools -> Maven -> Runner.

You will see the following screen, and you need to enable the “Delegate IDE build/run actions to Maven”. This will delegate most tasks to maven and should let IntelliJ play nice with WSL2. After enabling this feature, I was able to use Run, build, and use Maven from IntelliJ.



Delegating build and run tasks to Maven inside IntelliJ fixed the Maven issues I had while using it with WSL2. Hope this also fixes your WSL2 IntelliJ issues 🙂.


Questions, comments, concerns?

Have a question or comment about the content? Feel free to reach out!