Skip to content

Fix parsing of maven-wrapper.properties in mvnw.cmd script #189

@coderabbitai

Description

@coderabbitai

Problem

The PowerShell section of the mvnw.cmd script fails to parse the maven-wrapper.properties file properly when it contains license header comments.

# Current problematic code
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl

Impact

When running the Maven wrapper on Windows, execution stops with the following error:

ConvertFrom-StringData : Data missing '=' in the string.

This happens because ConvertFrom-StringData expects every non-blank line to contain an '=' sign, but the properties file begins with ASF license header comments.

Proposed Solution

Modify the PowerShell code to strip comments and blank lines before parsing:

# Fixed approach
$properties = Get-Content "$scriptDir/.mvn/wrapper/maven-wrapper.properties" |
              Where-Object { $_ -match '^\s*[^#].*=' } |
              ConvertFrom-StringData
$distributionUrl = $properties.distributionUrl

This also provides the benefit of reusing $properties later instead of re-reading the file (see lines 124-125 in mvnw.cmd).

References

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions