Docker环境下Gradle构建Spring Boot应用时找不到指定插件问题
容器内Gradle构建无法找到com.gorylenko.gradle-git-properties插件的解决方案
问题描述
我正在将一个使用Gradle 6.9和JVM 1.8的Spring Boot应用容器化,本地构建完全正常,但在容器内执行构建时出现以下错误:
Plugin [id: 'com.gorylenko.gradle-git-properties', version: '1.4.15'] 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 'com.gorylenko.gradle-git-properties:com.gorylenko.gradle-git-properties.gradle.plugin:1.4.15') Searched in the following repositories: Gradle Central Plugin Repository
本地环境信息:
Gradle 6.9 Build time: 2021-05-07 07:28:53 UTC Revision: afe2e24ababc7b0213ccffff44970aa18035fc0e Kotlin: 1.4.20 Groovy: 2.5.12 Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020 JVM: 1.8.0_402 (Amazon.com Inc. 25.402-b08) OS: Windows 11 10.0 amd64
容器内环境信息:
Gradle 6.9 Build time: 2021-05-07 07:28:53 UTC Revision: afe2e24ababc7b0213ccffff44970aa18035fc0e Kotlin: 1.4.20 Groovy: 2.5.12 Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020 JVM: 1.8.0_292 (AdoptOpenJDK 25.292-b10) OS: Linux 5.15.133.1-microsoft-standard-WSL2 amd64
已尝试更换多种JDK的Gradle镜像、基于JDK8基础镜像手动安装Gradle,问题仍未解决。
解决方法
1. 补充插件仓库配置
Gradle 6.x 默认依赖Gradle Central Plugin Repository,但部分插件可能同时发布在Maven Central。显式添加双仓库配置确保解析路径完整:
- 在项目根目录的
settings.gradle中添加:
pluginManagement { repositories { gradlePluginPortal() mavenCentral() } }
- 同时在
build.gradle中确认仓库声明:
repositories { mavenCentral() gradlePluginPortal() }
2. 排查容器网络连通性
容器内无法访问插件仓库是常见诱因:
- 进入容器测试网络连通性:
curl -I https://plugins.gradle.org curl -I https://repo1.maven.org/maven2
- 若使用Docker Desktop,检查代理设置是否干扰容器网络,或确认容器已开启外部网络访问权限。
- 内网环境需在项目的
gradle.properties中配置代理:
systemProp.http.proxyHost=你的代理地址 systemProp.http.proxyPort=你的代理端口 systemProp.https.proxyHost=你的代理地址 systemProp.https.proxyPort=你的代理端口
3. 使用完整插件坐标声明
旧版本Gradle可能无法正确解析插件短ID,改用buildscript方式声明插件:
buildscript { repositories { gradlePluginPortal() mavenCentral() } dependencies { classpath 'com.gorylenko:gradle-git-properties:1.4.15' } } apply plugin: 'com.gorylenko.gradle-git-properties'
4. 挂载本地Gradle缓存到容器
利用本地已下载的缓存避免重复拉取:
docker run -v ~/.gradle:/root/.gradle 你的构建镜像 ./gradlew build
或在Dockerfile中使用多阶段构建,复制本地缓存到容器内。
5. 验证插件版本兼容性
确认1.4.15版本与Gradle 6.9、JDK 1.8的适配性,可尝试切换到兼容版本(如2.2.0):
plugins { id 'com.gorylenko.gradle-git-properties' version '2.2.0' }
内容的提问来源于stack exchange,提问作者kev14762
相关产品推荐
相关产品推荐

