Cannot exclude root project from build

Hi

I am using Gradle 4.2 for Spring Boot application. I would like to apply Spring Boot plugin to sub-projects of my project so I put this plugin into subprojects section. How my overall build fails because Spring Boot plugin is executed for root project, could not find main class and generates error.
Please advise how specify this plugin for sub-projects only.

plugins { id "io.spring.dependency-management" version "1.0.3.RELEASE" apply false }
plugins { id 'org.springframework.boot' version '1.5.7.RELEASE' }

allprojects  {
  apply plugin: 'maven'

  group = 'test'
}

subprojects {
  apply plugin: 'java'
  apply plugin: 'io.spring.dependency-management'
  apply plugin: 'org.springframework.boot'
  
  sourceCompatibility = 1.8
  targetCompatibility = 1.8

  ext {
      springVersion = '4.3.11.RELEASE'
      springBootVersion = '1.5.7.RELEASE'
  } 
  
  repositories {
    mavenLocal()
    
    mavenCentral()
  } 

  dependencies {
     compile("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
  }
}

The script is missing apply false for the boot plugin in the plugins block at the very top. That’s why it is applied to your root project.

1 Like

Thank you, @st_oehme

It works now. Does that mean if I add some plugin this way I don’t need to specify it in allprojects section as well?

plugins { id ‘org.springframework.boot’ version ‘1.5.7.RELEASE’ }

You still need to, otherwise it is only applied to the root project. We will improve this syntax so it can be used consistently everywhere instead of mixing plugins {} and apply plugin

1 Like