- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.6k
 
fix(maven): fix mvn not available in child process #33239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
          👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it 
  | 
    
| 
           The latest updates on your projects. Learn more about Vercel for GitHub. 
  | 
    
| 
           @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, | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
| 
           Thanks for trying out   | 
    
          
 you are welcome, we followed similar approach in internal plugin so it looks promising  | 
    
| 
           Look like it is only happening on my local env ;)  | 
    
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/mavenplugin, users encounter the following error:NX Failed to process project graph.
at ChildProcess. (/node_modules/@nx/maven/dist/plugins/maven-analyzer.js:126:20)
Root Cause
The
maven-analyzer.jsfile 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'sPATHenvironment variable, which is needed to locate themvnexecutable.This issue is particularly problematic when:
mise,asdf, orsdkmanSolution
Add
env: process.envto thespawnoptions to inherit environment variables from the parent process, including the criticalPATHvariable.Before:
After:
Testing
Tested with:
The fix allows the plugin to successfully locate and execute Maven commands.
Impact
This PR description clearly explains the issue, the root cause, and the solution in a way that maintainers and other developers can easily understand.