Using Environment variable to determine Maven home path

Answered

Hi y'all,

I'm trying to point IntelliJ towards a Maven home location that may or may not change. For example, let's say the path is C:\development\apache-maven-3.9.9. At a certain point, I decide to update Maven to C:\development\apache-maven-3.9.12.

Is there an easy way to tell all my IntelliJ workspaces that this is the new location? I tried:

  • Setting M2_HOME because some old questions suggested IntelliJ picks up on that. Didn't work.
  • Setting M2_HOME and setting %M2_HOME% as my Maven home path. Didn't work, IntelliJ doesn't resolve environment variables this way.
  • Creating a symlink C:\development\apache-maven-latest which points to C:\development\apache-maven-3.9.9 and replacing it every time I update Maven. That DOES work, but is more tedious than updating an environment variable

Am I missing some obvious solution here? Is there some environment variable I can set to tell IntelliJ “Hey, this is where Maven is, just use that”?

Thanks!

EDIT: The documentation says:

"Use this list to select a bundled Maven version that is available (for Maven3, version 3.1 and later) or the result of resolved system variables such as MAVEN_HOME." So it seems to me that it SHOULD be possible, I just cannot figure out how.

0
1 comment
IntelliJ IDEA does not read the Maven home from an environment variable, and the **Maven home path** field does not expand `%M2_HOME%` or other variables. When `M2_HOME` or `MAVEN_HOME` points to a valid Maven installation, the IDE only adds that folder to the **Maven home path** list as a fixed path. The path you pick is saved in each project's own settings, so a later change of the variable does not reach the projects.

A link with a stable name, as you set up, is the way to keep all projects on one path. With a directory junction, the switch to a new Maven version is two commands. I haven't tested this exact sequence, but `rmdir` on a junction removes only the link, not the Maven folder it points to:

```
rmdir C:\development\apache-maven-latest
mklink /J C:\development\apache-maven-latest C:\development\apache-maven-3.9.12
```

If your projects have a Maven wrapper (`.mvn/wrapper/maven-wrapper.properties`), you can let each project choose its Maven version instead. Open **Settings | Build, Execution, Deployment | Build Tools | Maven**, and in **Maven home path** select **Use Maven wrapper**. The version is then set per project in the wrapper file, not in one central place. The [Maven help page](https://www.jetbrains.com/help/idea/2026.3/maven-support.html#maven2_install) describes both options.

One Maven home for all existing projects is requested in [IJPL-8661](https://youtrack.jetbrains.com/issue/IJPL-8661). Vote for it and follow it to get updates.
0

Please sign in to leave a comment.