Maven 错误“未知生命周期阶段”.test.skip=true“.....”

Yas*_*dev 8 java maven

当我尝试安装maven时,我在intellij中收到此错误,我尝试了此处提出的所有解决方案“/sf/ask/355184441/”,但它不起作用

PS C:\Users\stagiaire1\Desktop\Vgc\vgc-backend>  mvn clean install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------< com.dzadvisory:bankapp >-----------------------
[INFO] Building bankapp 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.344 s
[INFO] Finished at: 2022-09-21T16:51:00+01:00
[INFO] ------------------------------------------------------------------------
[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 phas
es 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-com
pile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-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
Run Code Online (Sandbox Code Playgroud)

小智 26

这是因为 PowerShell 将“-”解释为 PowerShell 参数。(您的终端在第一行显示“PS”)

所以你应该用 --% 来转义 PowerShell 参数,比如

 mvn clean install --% -Dmaven.test.skip=true
Run Code Online (Sandbox Code Playgroud)


Ted*_*lis 0

无法将其放在评论中,没有足够的代表。

这里很少有东西,下面描述的操作属于 Maven Surefire 插件,您需要确保它位于 pom 内的构建条目中

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>x.x.x</version>
      <configuration>
        <skipTests>${skipTests}</skipTests>
      </configuration>
    </plugin>
  </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

现在您将有三个选项来跳过测试。

  1. 正如您提到的使用 -Dmaven.test.skip 这既不会运行也不会编译任何测试,这意味着任何依赖于可用测试工件的测试都将失败
  2. 您可以使用 -DskipTests 它将编译但不运行您的测试,这意味着任何依赖于测试工件的内容都将能够继续
  3. 您可以使用上面声明的配置属性(skipTests),该属性可以在您的pom属性中设置