简体   繁体   中英

plugin with id spring-boot not found in parent build.gradle

I have below project structure:

java/
build.gradle
settings.gradle
projectA/
build.gradle
projectB/
build.gradle

When I put below codes in, eg projectA's 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'
...

everything works fine.

But if I put the above code in Java's 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'
    ...
}

When running gradle clean build, it keeps reporting below error:

Plugin with id 'spring-boot' not found.

Anyone encountered this issue before? And why?

I figured out a solution but don't know why. Will spent some time reading the docs during the weekend...

Change multi-project build.gradle to below:

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'
    ...
}

ie move buildscript out of subprojects

Try using fully qualified name as below:

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

You need to specify version of some plugins, you just have to. But gradle doesn't want multiple different versions, even though you type the same version in multiple files, if they include each other it won't work.

So to fix that you have to move common plugin to the root project, it doesn't matter if some projects don't use it, read further. Here is the trick part, you need to put apply false in the root project to the plugins. Thanks to that it won't be applied to the root and other projects but it will be applied to all of the projects you will add the plugin to.

So in root you would put:

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

But in subproject you put it without the version

plugins {
    id 'org.springframework.boot'
}

Also don't forget to put include statements in the root project, for all the folders that root needs to apply to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM