version selection breaks if maven specified in pom.xml is a variable

Issue #38 new
Matthew Ouyang created an issue

How to Reproduce

  • mvnvm installed
  • ruby installed
  • pom.xml has /project/prerequisites/maven set to something that is not a constant.

Example - Maven Compiler Plugin project has this value set to ${mavenVersion} which resolves to a property elsewhere in the file.

Root Cause - In line 124, the value in the XPath expression is taken as-is. There is no attempt to resolve the value further and the download will fail on a non-well-formed value.

Workaround - Have a mvnvm.properties with mvn_version set.

Suggested Fix - Only accept well-formed constants (ie no properties) in XPath of interest, and use the workaround in other cases. If we were to attempt to maven properties fully, we would also need to search the parent poms and system properties as well. Even if a library exists that can read pom files, it will increase the complexity of this tool.

Comments (5)

  1. Matthew Ouyang reporter
    • edited description

    I'd like to make a pull request that implements my suggested fix. Since I don't have write access, I pasted a patch below. Any feedback is welcomed.

    @@ -130,6 +130,10 @@ else
     end
     EOR
     ); then
    +        if [[ ! $project_mvn_version =~ "^\d+\.\d+(\.\d+)+$" ]]; then
    +          debug "Maven version in pom file at $dir does not follow the standard version numbering scheme.  Please set mvn_version in mvnvm.properties."
    +          exit 1;
    +        fi
             mvn_version="$project_mvn_version"
             mvn_version_configured=1
             debug "Found maven version in pom file at $dir, and set to $mvn_version"
    
  2. mjensenbitbucket-bot repo owner

    @mouyang If you fork the repo and create a pull request ill accept it. It may be to harsh to just exit, maybe ignore it and move on to a the default version is better.

  3. Log in to comment