尝试部署到 AZURE 时出错未能执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

Error when trying to deploy to AZURE Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test

嗨,开发者朋友,我需要帮助当我尝试从 github 部署到我的 Azure AppService 时,github 控制台显示以下错误。

嗨,开发人员朋友,我需要帮助当我尝试从 github 部署到我的 Azure AppService 时,github 控制台显示以下错误。

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) 项目 FastFoodApp: 有测试失败。

个别测试结果请参考/home/runner/work/Project-Name/target/surefire-reports。请参考转储文件(如果存在)[date].dump、[date]-jvmRun[N].dump 和 [date].dumpstream。 -> [帮助 1]

要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。重新运行 Maven 使用-X 开关启用完整的调试日志记录。

我已经尝试在 .yml 文件中添加 mvn clean install -DskipTests。同时在 pom.xml 文件中添加

<dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.5.2</version>
</dependency>

还有

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
            <testFailureIgnore>true</testFailureIgnore>
            </configuration>
</plugin>

我还尝试注释掉 src/test/java -> test.java

中的所有代码

但最后总是显示同样的错误

这是 .yml 文件

name: Build and deploy JAR app to Azure Web App - fastfoodapi

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Java version
        uses: actions/setup-java@v1
        with:
          java-version: '11'

      - name: Build with Maven
        run: mvn clean install

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: java-app
          path: '${{ github.workspace }}/target/*.jar'

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: java-app

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'fastfoodapi'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2896B985447E4F1D85D4FE3ECA3795AC }}
          package: '*.jar'

尝试以下步骤解决错误:

  • 右键单击项目 > 运行 作为 Maven 测试。
  • 会自动下载缺少的插件。
  • 右键单击项目>更新Maven项目,之后错误应该消失了。

参考文献:

  1. How to solve "failed to execute goal "maven-surefire-plugin:2.19.1" in maven
  2. Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test
  3. Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test