You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions中compileJava任务执行失败,请求排查解决

问题:GitHub Actions执行compileJava任务失败,提示Gradle弃用特性兼容问题

我在项目的.github/workflows目录下添加了coverage.yml文件,创建Pull Request后,GitHub Actions执行时compileJava任务失败,错误提示构建使用了已弃用的Gradle特性,与Gradle 7.0不兼容。我不确定是不是本地Mac安装多个JDK导致的,求解决方法。

coverage.yml 文件内容

name: Measure coverage

on:
  push:
    branches: [ develop ]
  pull_request:

jobs:
  build:
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: '11'

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Run Coverage
        run: ./gradlew test

      - name: Upload Report
        uses: 'actions/upload-artifact@v2'
        with:
          name: report.xml
          path: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml

      - name: Jacoco Report to PR
        id: jacoco
        uses: madrapps/jacoco-report@v1.1
        with:
          path: ${{ github.workspace }}/build/reports/jacoco/test/jacocoTestReport.xml
          min-coverage-overall: 90
          min-coverage-changed-files: 60
          debug-mode: false

      - name: Get the Coverage info
        run: |
          echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
          echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"

错误信息

Run ./gradlew test
Downloading https://services.gradle.org/distributions/gradle-6.7.1-all.zip
.............10%..............20%..............30%..............40%..............50%..............60%..............70%..............80%..............90%..............100%

Welcome to Gradle 6.7.1!

Here are the highlights of this release:
 - File system watching is ready for production use
 - Declare the version of Java your build requires
 - Java 15 support

For more details see https://docs.gradle.org/6.7.1/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)
> Task :bootBuildInfo
> Task :checkApolloVersions
> Task :generateMainServiceApolloSources
> Task :checkMainServiceApolloDuplicates
> Task :compileJava FAILED

FAILURE: Build failed with an exception.


* What went wrong:
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Execution failed for task ':compileJava'.
Use '--warning-mode all' to show the individual deprecation warnings.

解决方法

1. 排除本地JDK的影响

本地Mac安装多个JDK不会影响GitHub Actions的构建——Actions是在云端独立的macos-latest环境中运行,完全隔离于你的本地环境,所以这个可以排除。

2. 查看具体的弃用警告详情

修改coverage.yml中Run Coverage步骤的命令,添加--warning-mode all参数,这样能输出具体哪些Gradle特性被弃用,方便定位问题:

- name: Run Coverage
  run: ./gradlew test --warning-mode all

3. 排查compileJava失败的深层原因

弃用警告可能只是提示,真正导致任务失败的可能是编译错误。添加--stacktrace参数获取详细错误栈:

- name: Run Coverage
  run: ./gradlew test --warning-mode all --stacktrace

4. 升级GitHub Actions的JDK配置

当前使用的actions/setup-java@v1版本较旧,建议升级到最新稳定版v4,配置更可靠:

- name: Set up JDK 11
  uses: actions/setup-java@v4
  with:
    java-version: '11'
    distribution: 'temurin'

5. 检查项目Gradle配置

  • 打开项目根目录的build.gradle(或build.gradle.kts),排查是否使用了Gradle 7.0已移除的特性,比如旧插件的声明方式、过时的API调用。
  • 确认项目的Gradle wrapper版本:当前Actions使用的是6.7.1,如果项目依赖的插件要求更高版本的Gradle,需要更新项目的wrapper(本地执行./gradlew wrapper --gradle-version <目标版本>,然后提交变更)。

内容的提问来源于stack exchange,提问作者Sheetal Jain

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 22:49:56