解决IntelliJ IDEA下Maven报错Unknown lifecycle phase “.test.skip=true“. You must specify a valid lifecycle

解决IntelliJ IDEA下Maven报错Unknown lifecycle phase ".test.skip=true". You must specify a valid lifecycle phase or a goal in the format

  笔者使用 IntelliJ IDEA 中的终端(Terminal)来运行跳过单元测试时的命令 mvn package -Dmaven.test.skip=true 时,发现总是报如下的错:

笔者报错时的运行环境:

  • JDK 17
  • Maven 3.6.3
  • IntelliJ IDEA 2021.2.2 (Ultimate Edition)
[ERROR] Unknown lifecycle phase ".test.skip=true". You must specify a valid lifecycle phase or a goal in the format : or :[:

]:. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, genera te-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integr ation-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

  原来是因为 IntelliJ IDEA 的终端默认使用 PowerShell 来运行命令,而在 PowerShell 下,参数 -Dmaven.test.skip=true 没有被正确地识别。

解决IntelliJ IDEA下Maven报错Unknown lifecycle phase “.test.skip=true“. You must specify a valid lifecycle_第1张图片

  不过这只需要加在此参数外加单引号即可,即:mvn package '-Dmaven.test.skip=true'。也可以选择将 IntelliJ IDEA 的终端设置成 CMD 模式(Command Prompt),不过笔者通常不喜欢这样做,毕竟 PowerShell 比原始的 CMD 要强大。

解决IntelliJ IDEA下Maven报错Unknown lifecycle phase “.test.skip=true“. You must specify a valid lifecycle_第2张图片

你可能感兴趣的:(疑难杂症,Java,intellij-idea,maven,java,powershell,cmd)