在父build.gradle中找不到id spring-boot的插件

时间:2015-11-06 06:57:38

标签: java gradle spring-boot

我的项目结构如下:

的java /
的build.gradle
settings.gradle
了projectA /
的build.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'的插件。

之前有人遇到过此问题吗?为什么?

3 个答案:

答案 0 :(得分:8)

我找到了解决方案,但不知道为什么。会在周末花些时间阅读文档......

将多项目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'
    ...
}

即从子项目中移出buildscript

答案 1 :(得分:0)

尝试使用以下完全限定名称:

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

答案 2 :(得分:0)

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

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

所以在 root 中你会输入:

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

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

plugins {
    id 'org.springframework.boot'
}

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