【问题标题】:plugin with id spring-boot not found in parent build.gradle在父 build.gradle 中找不到 ID 为 spring-boot 的插件
【发布时间】:2016-02-07 06:26:05
【问题描述】:

我有以下项目结构:

java/
构建.gradle
settings.gradle
项目A/
构建.gradle
项目B/
build.gradle

当我输入以下代码时,例如projectA的build.gradle,

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
...

一切正常。

但是如果我把上面的代码放在Java的build.gradle中:

subprojects {
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
        }
    }

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'spring-boot'
    ...
}

运行gradle clean build时,一直报如下错误:

未找到 ID 为“spring-boot”的插件。

以前有人遇到过这个问题吗?为什么?

【问题讨论】:

    标签: java gradle spring-boot


    【解决方案1】:

    我想出了一个解决方案,但不知道为什么。周末会花一些时间阅读文档...

    将多项目 build.gradle 更改为以下内容:

    buildscript {
        repositories {
            mavenCentral()
        }
    
        dependencies {
                classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
        }
    }
    
    subprojects {
        apply plugin: 'java'
        apply plugin: 'eclipse'
        apply plugin: 'spring-boot'
        ...
    }
    

    即将构建脚本移出子项目

    【讨论】:

    【解决方案2】:

    尝试使用完全限定名称,如下所示:

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

    【讨论】:

      【解决方案3】:

      你需要指定一些插件的版本,你只需要。但是 gradle 不想要多个不同的版本,即使您在多个文件中键入相同的版本,如果它们相互包含,它将无法工作。

      因此,要解决您必须将通用插件移动到根项目的问题,如果某些项目不使用它也没关系,请进一步阅读。这是技巧部分,您需要将apply false 放入插件的根项目中。由于它不会应用于根项目和其他项目,但它将应用于您将添加插件的所有项目。

      所以你会在 root 中输入:

      plugins{
          id 'org.springframework.boot' version '2.0.3.RELEASE' apply false
      }
      

      但是在子项目中你把它没有版本

      plugins {
          id 'org.springframework.boot'
      }
      

      另外不要忘记将include 语句放在根项目中,用于根需要应用到的所有文件夹。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-22
        • 2020-12-30
        • 2019-01-17
        • 2018-01-29
        • 2023-03-19
        • 2021-03-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多