未找到 ID 为“org.springframework.boot”的插件

bur*_*ino 6 java spring gradle spring-boot

我想使用 gradle 5.2 将 spring boot 插件包含到我的项目中。下面是我的 build.gradle 的当前状态,接下来是我尝试做的事情。目前,我正在尝试使用 gradle 5 的BOM 支持,但这不是硬性要求。我只想知道如何解决错误

未找到 ID 为“org.springframework/boot”的插件

更新:更新了下面的结构以更好地代表我的用例。

构建.gradle

apply from: 'boot.gradle'
Run Code Online (Sandbox Code Playgroud)

引导.gradle

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

dependencies {
    implementation platform('org.springframework.boot:spring-boot-dependencies:2.0.0.RELEASE')

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.RELEASE'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.0.0.RELEASE'

    implementation group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.0.0.RELEASE'
}
Run Code Online (Sandbox Code Playgroud)

要重现我的错误,您只需要在项目中再添加一个文件:

应用程序.java

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

我已尝试实施此处找到的解决方案,该解决方案基于

在外部脚本(我们称之为脚本插件)中,不能使用插件 ID。相反,必须使用完全限定的类名。这是一个已知的错误。

并且这里这是不是为我工作,即使我升级使用Spring 2.0.5。

以及其他各种类似的解决方案。

Abd*_*ssi 5

您可以尝试使用 Spring BOM 依赖项管理,如下所示:

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
}

apply plugin: 'io.spring.dependency-management'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Run Code Online (Sandbox Code Playgroud)


bur*_*ino 2

我的用例的这个解决方案基于 Abdelghani 的答案。

构建.gradle

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
}

apply from: 'boot.gradle'
Run Code Online (Sandbox Code Playgroud)

启动.gradle

repositories {
    mavenCentral()
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

dependencies {
    implementation platform('org.springframework.boot:spring-boot-dependencies:2.0.0.RELEASE')

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.RELEASE'
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '2.0.0.RELEASE'

    implementation group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '2.0.0.RELEASE'
}
Run Code Online (Sandbox Code Playgroud)

简而言之,构建脚本需要有“org.springframework.boot”作为插件可以apply plugin: 'org.springframework.boot'在其他地方工作。