我试图从命令行构build我们的Web项目,但是跳过了testing。 我正在使用命令mvn clean install -Dmaven.test.skip=true
。
当我从传统的黑白命令提示符(又名DOS shell)运行命令的命令工作,但是当我从“Windows PowerShell”的命令运行它,我得到以下错误:
[ERROR] Unknown lifecycle phase ".test.skip=true". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin- artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepar e-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-site, site, post-site, site-deploy, pre-clean, clean, po st-clean. -> [Help 1]
是什么导致了这种差异,我如何让PowerShell的行为像传统的命令提示符?
这是在Windows 7上运行。
当遇到PowerShell解释传递给控制台EXE的参数的问题时,请尝试使用PowerShell社区扩展附带的echoargs.exe
实用程序。 有了这个工具,您可以看到PowerShell如何为EXE提供参数,例如:
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'
以下为我工作。
$mvnArgs1 ="mvn test -X -Dmaven.test.skip=true".replace('-D','`-D') Invoke-Expression $mvnArgs1
它看起来像-D是一种特殊的字符,需要逃脱。
还要注意,-X工作正常,不需要转义。 注意在replace命令中使用单引号,如果你使用双引号(即“”),则需要使用“`”。
我在Windows 7上使用Powershell 2.0(2.0.1.1)
根据这个电子邮件线程 :
一般来说,如果你正在使用Powershell for Maven,svn等,你最终不得不转义任何以短划线( – )开头的参数。 Powershell中的转义字符是反引号。 所以你最终得到了mvn原型:创建`-DgroupId = blah`-DartifactId = blah。 ,' – '是一个特殊的字符,当你从Powershell控制台运行maven时,需要用back-tick进行转义。