Skip to content

Conversation

@jogelin
Copy link
Contributor

@jogelin jogelin commented Oct 24, 2025

Description

Fixes the "spawn mvn ENOENT" error that occurs when the Maven executable is not found in the PATH of the spawned child process.

Problem

When using the @nx/maven plugin, users encounter the following error:

NX Failed to process project graph.

  • Error: Failed to spawn Maven process: spawn mvn ENOENT
    at ChildProcess. (/node_modules/@nx/maven/dist/plugins/maven-analyzer.js:126:20)

Root Cause

The maven-analyzer.js file spawns a child process to run Maven commands, but it doesn't pass environment variables to the spawned process. This means the child process doesn't inherit the parent's PATH environment variable, which is needed to locate the mvn executable.

This issue is particularly problematic when:

  • Maven is managed by version managers like mise, asdf, or sdkman
  • The Nx daemon is running (daemon processes have a different environment)
  • Maven is installed in a non-standard location that's in the user's PATH

Solution

Add env: process.env to the spawn options to inherit environment variables from the parent process, including the critical PATH variable.

Before:

const child = (0, child_process_1.spawn)(mavenExecutable, mavenArgs, {
    cwd: workspaceRoot,
    stdio: 'pipe',
});

After:

const child = (0, child_process_1.spawn)(mavenExecutable, mavenArgs, {
    cwd: workspaceRoot,
    stdio: 'pipe',
    env: process.env, // Inherit environment variables from parent process
});

Testing

Tested with:

  • Maven 3.9.5 managed by mise
  • Java 17 managed by mise
  • Nx 22.0.1 with @nx/maven 22.0.1

The fix allows the plugin to successfully locate and execute Maven commands.

Impact

  • ✅ Fixes Maven detection when using version managers
  • ✅ No breaking changes - purely additive
  • ✅ Improves compatibility with various development environments
  • ✅ Aligns with Node.js best practices for spawning child processes

This PR description clearly explains the issue, the root cause, and the solution in a way that maintainers and other developers can easily understand.

@netlify
Copy link

netlify bot commented Oct 24, 2025

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit d673c6c

@vercel
Copy link

vercel bot commented Oct 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Oct 24, 2025 2:36pm

@jogelin
Copy link
Contributor Author

jogelin commented Oct 24, 2025

@FrozenPandaz can you check

shell: true,
stdio: 'pipe', // Always use pipe so we can control output
stdio: 'pipe', // Always use pipe so we can control output,
env: process.env,
Copy link
Collaborator

@FrozenPandaz FrozenPandaz Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change technically does nothing because spawn defaults to process.env... 🤔

https://nodejs.org/api/child_process.html#child_processspawncommand-args-options

Did this somehow fix things for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it does...
let me reproduce it on clean repo

Copy link
Contributor Author

@jogelin jogelin Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try on this repo

https://github.com/jogelin/test-nx-maven

I am using mise which is providing mvn in the path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrozenPandaz did you try it?

@FrozenPandaz
Copy link
Collaborator

Thanks for trying out @nx/maven! 🙏

@jogelin
Copy link
Contributor Author

jogelin commented Oct 24, 2025

Thanks for trying out @nx/maven! 🙏

you are welcome, we followed similar approach in internal plugin so it looks promising

@jogelin
Copy link
Contributor Author

jogelin commented Nov 3, 2025

Look like it is only happening on my local env ;)

@jogelin jogelin closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants