Problem
Junie does not respect Maven settings and switches JDK when running Maven commands, despite the SDK is set to a certain version (e.g. 25).
Cause
The root of this is that Junie runs Maven in the shell environment in which IntelliJ IDEA was launched, so it inherits the system-level Java and environment variables rather than the JDK and Maven user settings configured in the IDE. There are two parts, each with a workaround that can be used until Junie respects the IDE configuration.
Resolution
- Junie uses the wrong JDK
Junie picks up whatever Java/JAVA_HOME is set to by default in the shell. If it does not match the JDK the project builds with, Maven fails with errors such as an unsupported release version, or the user is prompted to install another JDK already configured in the IDE.
Make the project's JDK the default for the shell, then relaunch the IDE:
-
In the shell profile (
~/.zshrcor~/.zprofileon macOS/Linux), pointJAVA_HOMEat the JDK your project targets and put it first on PATH:export JAVA_HOME=/path/to/your/project-jdk/Contents/Home export PATH="$JAVA_HOME/bin:$PATH" -
In a fresh terminal, outside the IDE, confirm it:
java -version echo $JAVA_HOMEBoth should report the version your project needs.
-
Fully quit and restart IntelliJ IDEA so it picks up the new environment, then run the build through Junie again.
-
This works in both directions. If your project needs Java 17 but the shell defaults to a newer JDK, set it to 17. If your project needs Java 25 but the shell defaults to 17, set it to 25. If JDKs are managed with SDKMAN, jenv, or asdf, set the default there and relaunch the IDE the same way.
-
Junie ignores a custom Maven settings.xml
If the project build depends on a custom user settings.xml configured in the IDE (for example an internal repository), Junie may not apply it, so dependency resolution fails. Maven's standard override works here. Run the command with -s pointing at the settings file:
mvn -s /path/to/your/settings.xml clean compile
It can also be asked to Junie to use that exact command, or run it directly in a terminal.
A note on guidelines: it is possible to record these instructions in .junie/guidelines.md (or AGENTS.md) so Junie sees them, but guidelines are advisory. They make the right behavior more likely, they do not force the JDK or the settings file. There is no project setting today that pins the JDK, JAVA_HOME, or the Maven settings file for Junie, which is what the issue Junie does not respect Maven settings and the project JDK when running Maven commands tracks.
Comments
0 comments
Please sign in to leave a comment.