./mvnw fails when executed on Windows Subsystem for Linux as well as Docker containers running on Windows
scheerer opened this issue · comments
Executing the ./mvnw bash script within a Docker container running on Windows or within the Windows Subsystem for Linux both result in the following error. Other bash shell scripts work as expected.
$ ./mvnw
: not found ./mvnw:
: not found ./mvnw:
./mvnw: 53: ./mvnw: Syntax error: word unexpected (expecting "in")
Here is another person encountering the same issue: https://serverfault.com/questions/925179/wsl-and-maven-wrapper
So .. any idea how to fix it? The script is probably confused by the mixed Windows / Linux setup or trips of some bash differences. it seems that the in keyword is not understood. Is this maybe a bug in bash of WSL? And if its on windows.. why not run the mvnw windows command?
Seems to be something with the line endings. I was able to get around this issue by re-downloading the maven wrapper in Windows, unzipping in Windows, then using those within the WSL and Docker envs. That seems to help (specifically seems to be the mvnw.cmd file)
As far as I'm concerned this ticket can be closed.
Thanks @scheerer: dos2unix mvnw
fixed the problem for me.
Apart from the fix mentioned above for those with the repo already checked out, another nice and more permanent fix for future repo cloners is to include instructions of how to checkout the mvnw
script in your git repo by adding this to your .gitattributes
files: mvnw text eol=lf
. This will ensure this script is always checked out with LF line endings.
More info here: https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings
Thank you!