Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.3.1
-
None
-
Linux
-
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.)