2011-06-14 105 views
29

我試圖從命令行構建我們的Web項目,但跳過了測試。我正在使用命令mvn clean install -Dmaven.test.skip=true無法在Microsoft Powershell中使用`mvn -D`參數運行Maven,但在命令提示符下運行

當我運行從傳統的黑色&白命令提示符(又名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

回答

76

運行當您運行與論據PowerShell的解釋問題被傳遞到一個控制檯EXE,請嘗試使用echoargs.exe工具自帶的PowerShell Community Extensions。有了這個工具,你可以看到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'

+2

哇,* GREAT *答案,希望我能投上一票兩次 – ArtB 2011-06-15 13:41:04

+2

恰好碰到了這是有關於「=」和分裂參數有什麼可能的原因看起來十分愚蠢的。「」? – Grod 2012-10-04 21:03:09

+0

好的答案。任何想法爲什麼PowerShell分裂-Dmaven.test.skip = true在第一階段,但不是後續那些? – Fopedush 2012-10-25 17:00:28

4

以下爲我工作。

$mvnArgs1 ="mvn test -X -Dmaven.test.skip=true".replace('-D','`-D') 
Invoke-Expression $mvnArgs1 

看起來-D是一種特殊字符,需要轉義。
還要注意,-X工作正常,不需要轉義。 注意在替換命令中使用單引號的,如果你用雙引號(即「),你需要使用``。

我在Windows上使用PowerShell 2.0(2.0.1.1)7

3

根據到this email thread

Generally if you are using Powershell for Maven, svn etc you end up having to escape any arguments which start with a dash (-). The escape character in Powershell is a backtick. So you end up with mvn archetype:create `-DgroupId=blah `-DartifactId=blah. , the '-' is a special character that needs escaping with a back-tick when you run maven from Powershell console.

相關問題