Issue
I want to read the local repository path of maven into a variable in a batch script.
When attempting to just retrieve the path via console, it works fine:
C:\Users\me>mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout
C:\Users\me\.m2\repository
But when running the same within a for-in loop in a batch file, it throws a MissingProjectException.
C:\Users\me>FOR /F "tokens=*" %%g IN ('mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout') do (SET LOCAL_REPO=%%g)
C:\Users\me>(SET LOCAL_REPO=[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\me). Please verify you invoked Maven from the correct directory. -> [Help 1] )
C:\Users\me>(SET LOCAL_REPO=[ERROR] )
C:\Users\me>(SET LOCAL_REPO=[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. )
C:\Users\me>(SET LOCAL_REPO=[ERROR] Re-run Maven using the -X switch to enable full debug logging. )
C:\Users\me>(SET LOCAL_REPO=[ERROR] )
C:\Users\me>(SET LOCAL_REPO=[ERROR] For more information about the errors and possible solutions, please read the following articles: )
C:\Users\me>(SET LOCAL_REPO=[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException )
I assume that it doesn't properly interpret the command here (perhaps because of the colon?), but I don't know what I'm doing wrong. Any help is greatly appreciated :)
Solution
FOR /F "tokens=*" %%g IN ('mvn help:evaluate "-Dexpression=settings.localRepository" -q -DforceStdout') do (SET LOCAL_REPO=%%g)
The -Dexpression flag needs to be put in quotation marks, otherwise it is split and 'settings.localRepository' is seen as a lifecycle phase.
Answered By - leyren
Answer Checked By - Mary Flores (JavaFixing Volunteer)