Search code examples
gradlegradle-kotlin-dsl

Unable to apply plugin in gradle init script


Here is my gradle init script.

initscript {
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }

    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
    }
}

allprojects {
    apply(plugin="java")
    apply(plugin="application")
    apply(plugin="org.springframework.boot.gradle.plugin.SpringBootPlugin")
    repositories {
        gradlePluginPortal()
        mavenCentral()
    }

}

However, I am getting Plugin with id 'org.springframework.boot.gradle.plugin.SpringBootPlugin' not found. error.

I have tried the solutions from the following questions but none of them solves the problem.

Add Android plugin to gradle init script


Solution

  • I have found my solution after googling around.

    In order to apply plugins in gradle init script that is written in kotlin DSL, one has to use the following

    initscript {
        repositories {
            gradlePluginPortal()
            mavenCentral()
        }
    
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:2.5.1")
        }
    }
    
    allprojects {
        apply(plugin="java")
        apply(plugin="application")
        apply<org.springframework.boot.gradle.plugin.SpringBootPlugin>()
        repositories {
            gradlePluginPortal()
            mavenCentral()
        }
    
    }
    

    In order to apply third party plugins in the init script, one has to use the form apply<path.to.classname>()