Gradle初始化脚本中无法应用Spring Boot插件问题求助
Fix: "Plugin with id 'org.springframework.boot.gradle.plugin.SpringBootPlugin' not found" in Gradle Init Script
Let's break down what's going wrong here and fix it step by step:
The Core Issue
You're trying to apply the Spring Boot Plugin using its full Java class name (org.springframework.boot.gradle.plugin.SpringBootPlugin) instead of its official Gradle plugin ID. Gradle uses plugin IDs to resolve and apply plugins, not the full class path.
Corrected Init Script
Here's the adjusted version of your init script that should work:
initscript { repositories { gradlePluginPortal() mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1") } } allprojects { apply plugin: "java" apply plugin: "application" // Use the official plugin ID instead of the full class name apply plugin: "org.springframework.boot" // Optional: Add dependency management plugin to handle Spring Boot BOM apply plugin: "io.spring.dependency-management" repositories { gradlePluginPortal() mavenCentral() } }
Key Explanations
- Plugin ID vs Class Name: The Spring Boot Plugin's standard ID is
org.springframework.boot— this is what Gradle expects when usingapply plugin:. The full class name is only used in specific scenarios (like custom plugin implementations), not for official plugins from the portal. - Dependency Management Plugin: Adding
io.spring.dependency-managementis optional but highly recommended. It automatically imports Spring Boot's Bill of Materials (BOM), which manages consistent versions for all Spring Boot-related dependencies, so you don't have to specify versions manually. - Version Compatibility: Double-check that your Gradle version is compatible with Spring Boot 2.5.1. This plugin version requires Gradle 6.8.x to 7.3.x. Run
./gradlew --versionto verify your installed Gradle version.
Quick Troubleshooting
- If you still see issues, confirm your network can access
gradlePluginPortal()andmavenCentral()— sometimes corporate proxies or firewalls block these repositories. - Clear your Gradle cache (usually in
~/.gradle/caches) and try running your build again to rule out corrupted cached dependencies.
内容的提问来源于stack exchange,提问作者Mox
相关产品推荐
相关产品推荐

