takari / maven-wrapper

The easiest way to integrate Maven into your project!
Apache License 2.0
1.59k stars 234 forks source link

Fix bug in Windows Maven Wrapper script #179

Open baincd opened 3 years ago

baincd commented 3 years ago

(I am aware that this project is frozen. However, this version of maven wrapper is still very common, including in new projects generated by Spring Initializr. Therefore, I request this be kept open as documentation for others on how to resolve this issue.)

The mvnw.cmd script that has a bug in the functionality that should loop over the .mvn/wrapper/maven-wrapper.properties, which causes the properties to not take effect. This is especially problematic in development environments that require the use of a maven repository other than Maven Central.

To fix the issue, in mvnw.cmd edit the FOR loop at lines 125-127 to add the usebackq option

FOR /F "tokens=1,2 delims== usebackq" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
    IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)

Explanation: The double quotes around the filename causes the FOR command to treat it as string. But adding the usebackq option changes the FOR command to instead treat the double-quoted string as a filename set (reference)

jvanzyl commented 3 years ago

I will integrate this and likely do a release, as the version at Apache is currently unusable for 3.x users and will continue to be.