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

Jer*_*Xue 5 java gradle spring-boot

我有以下项目结构:

java/
  build.gradle
  settings.gradle
  projectA/
    build.gradle
  projectB/
    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'
...
Run Code Online (Sandbox Code Playgroud)

一切正常.

但是如果我把上面的代码放在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'
    ...
}
Run Code Online (Sandbox Code Playgroud)

运行gradle clean build时,它会报告以下错误:

没有找到id为'spring-boot'的插件.

有没有人遇到过这个问题?为什么?

Jer*_*Xue 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'
    ...
}
Run Code Online (Sandbox Code Playgroud)

即从子项目中移出buildscript