我已经开始使用 GitHub Actions 实现 CI-CD 并将 lint 集成到 中main.yml
,但是出现了如下错误:
Run ./gradlew lintDebug
Downloading https://services.gradle.org/distributions/gradle-8.0-bin.zip
...........10%............20%............30%............40%............50%............60%...........70%............80%............90%............100%
Welcome to Gradle 8.0!
For more details see https://docs.gradle.org/8.0/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* Where:
Build file '/home/runner/work/ci-cd-example/ci-cd-example/app/build.gradle.kts' line: 1
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Your current JDK is located in /usr/lib/jvm/temurin-11-jdk-amd64
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1m 22s
Error: Process completed with exit code 1.
我已将 Java 版本更改为 17。以下是我通过在终端中JAVA_HOME
应用命令获得的版本详细信息(我使用的是 Mac)java -version
openjdk version "17.0.8.1" 2023-08-24
OpenJDK Runtime Environment Homebrew (build 17.0.8.1+0)
OpenJDK 64-Bit Server VM Homebrew (build 17.0.8.1+0, mixed mode, sharing)
我还检查了代码的 Gradle JDK 版本,它也设置了JAVA_HOME
。
在这里,我想知道 GitHub 使用哪个 JDK 来运行该main.yml
文件,以及我是否可以更改 GitHub Actions 的 JDK 配置。
答案1
看起来您没有在.github/workflows.main.yml
文件中外部提及 JDK 版本。
外部提及的方式如下:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
- name: Set up Java
uses: actions/setup-java@v2
with:
distribution: "temurin"
java-version: 17