-
Notifications
You must be signed in to change notification settings - Fork 1
fix(scripts): make mvnw invocation cross-platform for Windows support #950
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env node | ||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * Cross-platform Maven wrapper runner. | ||||||||||||||||||||||||||||||||||||||||||||
| * Resolves ./mvnw (Unix) or mvnw.cmd (Windows) automatically. | ||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||
| * Usage: node --import tsx scripts/run-mvnw.ts [maven-args...] | ||||||||||||||||||||||||||||||||||||||||||||
| * Example: node --import tsx scripts/run-mvnw.ts pmd:check -q | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| import { spawnSync } from "node:child_process"; | ||||||||||||||||||||||||||||||||||||||||||||
| import path from "node:path"; | ||||||||||||||||||||||||||||||||||||||||||||
| import process from "node:process"; | ||||||||||||||||||||||||||||||||||||||||||||
| import { fileURLToPath } from "node:url"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||||||||||||||||||||||||||||||||||||||||||||
| const mvnwDir = path.resolve(__dirname, "..", "server", "application-server"); | ||||||||||||||||||||||||||||||||||||||||||||
| const isWindows = process.platform === "win32"; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| function main(): void { | ||||||||||||||||||||||||||||||||||||||||||||
| // shell: true is required on Windows for .cmd files (CVE-2024-27980). | ||||||||||||||||||||||||||||||||||||||||||||
| // Safe here because args come from hardcoded npm scripts, not user input. | ||||||||||||||||||||||||||||||||||||||||||||
| const result = spawnSync( | ||||||||||||||||||||||||||||||||||||||||||||
| isWindows ? "mvnw.cmd" : "./mvnw", | ||||||||||||||||||||||||||||||||||||||||||||
| process.argv.slice(2), | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| stdio: "inherit", | ||||||||||||||||||||||||||||||||||||||||||||
| cwd: mvnwDir, | ||||||||||||||||||||||||||||||||||||||||||||
| shell: isWindows, | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+28
|
||||||||||||||||||||||||||||||||||||||||||||
| function main(): void { | |
| // shell: true is required on Windows for .cmd files (CVE-2024-27980). | |
| // Safe here because args come from hardcoded npm scripts, not user input. | |
| const result = spawnSync( | |
| isWindows ? "mvnw.cmd" : "./mvnw", | |
| process.argv.slice(2), | |
| { | |
| stdio: "inherit", | |
| cwd: mvnwDir, | |
| shell: isWindows, | |
| const mvnwPath = path.join(mvnwDir, isWindows ? "mvnw.cmd" : "mvnw"); | |
| function main(): void { | |
| // Run the Maven wrapper directly to avoid shell interpretation of arguments. | |
| const result = spawnSync( | |
| mvnwPath, | |
| process.argv.slice(2), | |
| { | |
| stdio: "inherit", | |
| cwd: mvnwDir, |
Copilot
AI
Mar 26, 2026
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.
On Windows shell: true means the spawned process is cmd.exe, so a missing mvnw.cmd typically won’t surface as result.error/ENOENT; instead you’ll get a non-zero status (often 9009) and a generic shell message. If you want the actionable “wrapper not found” error cross-platform, check for the wrapper file’s existence before spawning (or explicitly detect the Windows command-not-found exit code and print the same message).
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.
echo 'Report: ...'is Bash-friendly, but on Windowscmd.exeit prints the single quotes literally. Since this script is being made Windows-compatible, consider switching toecho Report: ...(no quotes) or printing via Node so the output is consistent across shells.