问题
The command below works in command line
mvn clean install -Denunciate.skip
But breaks in powershell with the error
[ERROR] Unknown lifecycle phase ".skip". You must specify a valid lifecycle phase or a goal in the format
回答1:
Using quotes can help, especially with actual PowerShell code. However you are just trying to use a regular command. You can keep the PowerShell parser from misinterpreting your code by using the stop-parsing parameter
The stop-parsing symbol (
--%
), introduced in Windows PowerShell 3.0, directs Windows PowerShell to refrain from interpreting input as Windows PowerShell commands or expressions.When calling an executable program in Windows PowerShell, place the stop-parsing symbol before the program arguments. This technique is much easier than using escape characters to prevent misinterpretation.
So for your command you could have also done this.
mvn --% clean install -"Denunciate.skip"
If you did have variables mixed in there then just move the stop parser as needed.
回答2:
With trial and error this worked for me (I treated Denunciate.skip as a string by enclosing it in quotation marks)
mvn clean install -"Denunciate.skip"
回答3:
I feel I have to confirm and to add to developer747's answer. The double quotes need to completely wrap each argument in order for PowerShell to stop processing of the argument contents. (No monkeying around placing double quotes way deep into the argument as in -foo.bar="baz"
).
At the PowerShell prompt:
function detect() { write-host "in detect"; write-host "arg 0: $($args[0])"; write-host "arg 1: $($args[1])"; } exit detect "-foo.bar=baz"
in detect arg 0: -foo.bar=baz arg 1:
At the PowerShell prompt:
function detect() { write-host "in detect"; write-host "arg 0: $($args[0])"; write-host "arg 1: $($args[1])"; } exit detect -foo.bar=baz
in detect arg 0: -foo arg 1: .bar=baz
At the PowerShell prompt:
function detect() { write-host "in detect"; write-host "arg 0: $($args[0])"; write-host "arg 1: $($args[1])"; } exit detect -foo.bar="baz"
in detect arg 0: -foo arg 1: .bar=baz
To pass the double quotes from CMD to PowerShell, I had to prefix them with backslashes (not with carets!),
At the CMD prompt:
powershell -Command function detect() { write-host "in detect"; write-host "arg 0: $($args[0])"; write-host "arg 1: $($args[1])"; } exit detect \"-bar.foo=baz\"
in detect arg 0: -bar.foo=baz arg 1:
来源:https://stackoverflow.com/questions/31166828/how-to-handle-dots-in-powershell-commands