takari / maven-wrapper

The easiest way to integrate Maven into your project!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Running mvnw wrapper from another directory fails

teoincontatto opened this issue · comments

I found this to be an issue for me when running the wrapper in a CI environment to build dependencies that includes the maven wrapper and are located in another directory. The wrapper end with following error (xxx is the path from where I am running the wrapper command) :

/xxx/$ bash target/dependency/mvnw clean install -f target/dependency/pom.xml
line 276: /xxx/.mvn/wrapper/maven-wrapper.properties: No such file or directory

The script could be patched by changing line 197 of mvnw (not sure if there is a fix for windows version) by putting there following line:

BASE_DIR=`find_maven_basedir "$(basedir "$0")"`

had a similar issue. solved it by removing the workaround at mvnw#L181

I have same issue too.

I think it seems BASE_DIR value in mvnw set as pwd
So, i changed BASE_DIR like below

THIS=$(readlink -f $0)
BASE_DIR=${THIS%/*}

It could be maven version related issue. I'm using wrapper with maven version 3.6.3 and doesn't have any topic related issue.

find_maven_basedir in wrapper script does not parse -f option. #157 syncs this function to the same logic as maven 3.6.3, and should fix issue.

I'm running maven-wrapper 0.5.6 with maven 3.6.3 and I still get this issue.

cat .mvn/wrapper/maven-wrapper.properties
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar

and I still get the issue I cannot run outside the directory mvnw as I'm getting

$ cd other-directory
$ directory-to-mvnw-project/mvnw --version

directory-to-mvnw-project/mvnw: line 276: **other-directory**/.mvn/wrapper/maven-wrapper.properties: No such file or directory
**other-directory**/.mvn/wrapper/maven-wrapper.jar: No such file or directory
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain

from the comments it is not clear to me how can this be fixed in the wrapper itself. I cannot modify the contents of mvnw, so I would like if possible to have this fixed.

If you can give me some pointers, I can gladly create a PR with a fix.

Maven wrapper was never supposed to be used from another directory.

Seems a bit weird that this is closed since I am not the only one with this problem.
gradlew works fine with running from any directory, so I assumed this would work the same for the maven wrapper.
I don't think having this as a feature is something that complicates things or am I missing something?

We can look at implementing this after our migration in the next weeks. Stay tuned please.