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

执行Gradle命令失败:无法找到foojay-resolver-convention插件

Gradle构建失败:无法找到foojay-resolver-convention插件

问题详情

执行gradle tasks --all和gradle build命令时均出现构建失败,错误日志如下:

C:\Users\firstJavaProject>gradle build

FAILURE: Build failed with an exception.

* Where:
Settings file 'C:\Users\firstJavaProject\settings.gradle' line: 20


* What went wrong:
Plugin [id: 'org.gradle.toolchains.foojay-resolver-convention', version: '0.4.0'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.gradle.toolchains.foojay-resolver-convention:org.gradle.toolchains.foojay-resolver-convention.gradle.plugin:0.4.0')
  Searched in the following repositories:
    Gradle Central Plugin Repository

    Google
    MavenRepo

* 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 813ms

已尝试插件管理操作但问题未解决,当前环境配置:

  • Java版本:java 17.0.12 2024-07-16 LTS
  • Gradle版本:Gradle 8.1.1

settings.gradle文件内容:

plugins {
    // Apply the foojay-resolver plugin to allow automatic download of JDKs
    id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0'
}

解决步骤

1. 匹配插件与Gradle版本兼容性

foojay-resolver-convention:0.4.0要求Gradle版本至少为8.6,而当前使用的Gradle 8.1.1不满足该要求,导致插件无法被解析。可选择以下两种方案之一:

  • 升级Gradle到8.6及以上版本
  • 将插件版本降级到0.3.0(该版本适配Gradle 8.1.x系列)

2. 完善插件仓库配置

在settings.gradle中明确配置插件仓库,确保Gradle能正确检索到插件资源:

pluginManagement {
    repositories {
        gradlePluginPortal() // 优先使用Gradle官方插件仓库
        mavenCentral()
        google()
    }
}

plugins {
    id 'org.gradle.toolchains.foojay-resolver-convention' version '0.3.0'
}

3. 清理缓存并重新构建

执行以下命令清理本地Gradle缓存,强制重新拉取依赖和插件:

gradlew clean build --refresh-dependencies

4. 备选方案:手动引入插件依赖

如果上述方法无效,可直接在settings.gradle中通过buildscript方式引入插件:

buildscript {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }
    dependencies {
        classpath 'org.gradle.toolchains:foojay-resolver-convention:0.3.0'
    }
}

apply plugin: 'org.gradle.toolchains.foojay-resolver-convention'

内容的提问来源于stack exchange,提问作者Narendra Murthy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 14:23:10