I'm afraid, you can't do that easily. If you look at the mvn
script you can see it does not put $MAVEN_OPTS
in quotes.
So unless there is a trick I'm not aware of, there is no way to escape the space.
You can fix that locally by editing your mvn
script. If you used homebrew
to install Maven you can find it in /usr/local/Cellar/maven/<VERSION>/libexec/bin/mvn
. Make a copy of the script (so you can restore it if something goes wrong) and then find those lines at the end of the file (may be a bit different depending on the version):
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "${CLASSWORLDS_JAR}" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmaven.home=${MAVEN_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"
and add quotes around the variables so it looks like this:
exec "$JAVACMD" \
"$MAVEN_OPTS" \
"$MAVEN_DEBUG_OPTS" \
-classpath "${CLASSWORLDS_JAR}" \
"-Dclassworlds.conf=${MAVEN_HOME}/bin/m2.conf" \
"-Dmaven.home=${MAVEN_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${CLASSWORLDS_LAUNCHER} "$@"
I am not sure if this is a Maven bug or it's this way on purpose. It looks like the issue was reported already but there seems to be some pushback from the maven team.
UPDATE
After reading through the comments of the above issue, I found this one which explains why this may not be a good solution after all:
If you quote $MAVEN_OPTS
when used here, the java executable will see it as 1 parameter, not multiple ones, so if you have MAVEN_OPTS="-Xmx256m -Dparam=\"with space\""
, then java will understand a Xmx
value of 256m -Dparam="with space"
...
If you don't quote it, then every space separated token (even if it was escaped when declaring MAVEN_OPTS
) will be considered a separate argument, so -Dparam="with space"
will be understood as trying to launch the space"
main class with the -Dparam="with system property
...