Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-5786

Variable maven.multiModuleProjectDirectory may be set incorrectly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.3.1
    • Fix Version/s: 3.3.9
    • Component/s: Bootstrap & Build
    • Labels:
      None
    • Environment:
      Linux
    • Flags:
      Patch

      Description

      Consider the following sequence of commands, executed using the attached dummy-project.zip:

      $ cd /tmp/
      $ unzip dummy-project.zip
      Archive:  dummy-project.zip
         creating: dummy/
         creating: dummy/.mvn/
         creating: dummy/project/
         creating: dummy/project/.mvn/
        inflating: dummy/project/pom.xml   
      $ cd dummy/project/
      $ mvn help:effective-pom | grep effectiveMultiModuleProjectDirectory
          <effectiveMultiModuleProjectDirectory>/tmp/dummy</effectiveMultiModuleProjectDirectory>
      

      As you can see, the maven.multiModuleProjectDirectory variable is set to /tmp/dummy, even though the project is executed from within /tmp/dummy/project, which itself also contains a .mvn directory.

      Based on MNG-5767 and the comments in the relevant change, I suspect this is a bug. The find_maven_basedir function should test for the presence of .mvn before traversing to the current working directory's parent directory.

      Suggested fix:

      diff --git a/apache-maven/src/bin/mvn b/apache-maven/src/bin/mvn
      index 902de4a..5b6fed4 100755
      --- a/apache-maven/src/bin/mvn
      +++ b/apache-maven/src/bin/mvn
      @@ -199,12 +199,14 @@ fi
       find_maven_basedir() {
         local basedir=$(pwd)
         local wdir=$(pwd)
      -  while [ "$wdir" != '/' ] ; do
      -    wdir=$(cd "$wdir/.."; pwd)
      +  while true ; do
           if [ -d "$wdir"/.mvn ] ; then
             basedir=$wdir
             break
      +    elif [ "$wdir" = '/' ] ; then
      +      break;
           fi
      +    wdir=$(cd "$wdir/.."; pwd)
         done
         echo "${basedir}"
       }
      

      Two notes:

      • I didn't check whether this issue affects mvn.cmd, as I'm not familiar with Windows shell scripts and do not have a Windows machine at my disposal.
      • The patch does not simply move the wdir assignment below the if-statement, because that would break the case in which there is a sole .mvn in the file system root. (That'd be weird, yes, but allowed.)

        Attachments

        1. dummy-project.zip
          1 kB
          Stephan Schroevers

          Issue Links

            Activity

              People

              • Assignee:
                khmarbaise Karl Heinz Marbaise
                Reporter:
                stephan202 Stephan Schroevers
              • Votes:
                3 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: