无法在Microsoft Powershell中使用`mvn -D`参数运行Maven,但在命令提示符下可以使用 [英] Cannot run Maven using `mvn -D` argument within Microsoft Powershell, but works in Command Prompt

查看:2933
本文介绍了无法在Microsoft Powershell中使用`mvn -D`参数运行Maven,但在命令提示符下可以使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从命令行构建我们的web项目,但跳过测试。我使用命令 mvn clean install -Dmaven.test.skip = true

I am trying to build our web project from the commandline but skipping the testing. I am using the command mvn clean install -Dmaven.test.skip=true.

从传统的黑&白命令提示符(也称为DOS shell)的命令工作,但是当我从命令从Windows PowerShell运行它时,我得到以下错误:

When I run the command from the traditional black & white Command Prompt (aka DOS shell) the command works, but when I run it from the command from "Windows PowerShell" I get the following error:

[ERROR]未知的生命周期阶段.test.skip = true。您必须以< plugin-prefix>:< goal>格式指定有效的生命周期阶段或目标或< plugin-group-id>:< plugin-
artifact-id> [:< plugin-version>]:< goal> ;.可用的生命周期阶段是:validate,initialize,generate-sources,process-sources,generate-resources,process-resources,
compile,process-classes,generate-test-sources,process-test-sources,generate- -resources,process-test-resources,test-compile,process-test-classes,test,prepar
e-package,package,pre-integration-test,integration-test,post-integration-test,安装,部署,站点前,站点,站点后,站点部署,预清洁,清洁,po
st-clean。 - > [帮助1]

导致这种差异是什么,我如何让PowerShell的行为像传统的命令提示符?

What is causing this discrepancy and how do I get PowerShell to behave like the traditional Command Prompt?

这是在Windows 7上运行。

This is running on Windows 7.

推荐答案

当遇到PowerShell解释问题的参数传递到控制台EXE,请尝试使用附带的 echoargs.exe 实用程序PowerShell社区扩展。使用此工具,您可以看到PowerShell如何将参数提供给EXE例如:

When you run into problems with PowerShell's interpretation of arguments to be passed to a console EXE, try using the echoargs.exe utility that comes with the PowerShell Community Extensions. With this tool you can see how PowerShell supplies the arguments to the EXE e.g.:

PS> echoargs mvn clean install -Dmaven.test.skip=true
Arg 0 is <mvn>
Arg 1 is <clean>
Arg 2 is <install>
Arg 3 is <-Dmaven>
Arg 4 is <.test.skip=true>

PS> echoargs mvn clean install '-Dmaven.test.skip=true'
Arg 0 is <mvn>
Arg 1 is <clean>
Arg 2 is <install>
Arg 3 is <-Dmaven.test.skip=true>

简短回答 - 使用引号' - Dmaven .test.skip = true'

这篇关于无法在Microsoft Powershell中使用`mvn -D`参数运行Maven,但在命令提示符下可以使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆