[
https://issues.apache.org/jira/browse/MNG-6858?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17074632#comment-17074632
]
Joseph Walton commented on MNG-6858:
------------------------------------
If you know that have a Bash script, you can use the technique in [this Unix
Stack Exchange answer|https://unix.stackexchange.com/a/446848]. To paraphrase:
{code:java}
params=()
if [ "${ANDROID}" = "true" ]; then
params+=(-Pandroid)
fi
...
mvn "${params[@]}" ...
{code}
This could be less surprising than Maven silently ignore empty strings (always?
Only when they'd otherwise be goals?).
> Need a way to skip empty-string arguments
> -----------------------------------------
>
> Key: MNG-6858
> URL: https://issues.apache.org/jira/browse/MNG-6858
> Project: Maven
> Issue Type: Improvement
> Components: Command Line
> Affects Versions: 3.6.1
> Environment: Ubuntu 19.10
> Reporter: Chris Hennick
> Priority: Major
>
> I have a bash script that sets a sometimes-empty variable as follows:
>
> {code:java}
> if [ "${ANDROID}" = "true" ]; then
> MAYBE_ANDROID_FLAG=-Pandroid
> else
> MAYBE_ANDROID_FLAG=
> fi{code}
>
> It's used like so:
>
> {code:java}
> mvn ${MAYBE_ANDROID_FLAG} clean compile jacoco:instrument
> jacoco:prepare-agent test jacoco:restore-instrumented-classes jacoco:report
> -e -B}}{code}
>
> Shell-scripting best practices dictate that ${MAYBE_ANDROID_FLAG} above
> should be in double quotes, but when I do that, I get 'Unknown lifecycle
> phase ""'. For it to be possible to follow best practices, then, we need a
> way to make Maven skip over command-line arguments that are empty strings.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)