1

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

Mox
  • 2,355
  • 2
  • 26
  • 42
  • The plugin ID of the Spring Boot plugin is [`org.springframework.boot`](https://plugins.gradle.org/plugin/org.springframework.boot), not `org.springframework.boot.gradle.plugin.SpringBootPlugin`. – aSemy Jun 19 '22 at 14:39
  • `initscript` should be `buildscript`. – Martin Zeitler Jun 19 '22 at 14:41
  • @aSemy I have tried that initially and it does not work. – Mox Jun 19 '22 at 14:48
  • @MartinZeitler this is init script that is found in `init.d`. buildscript does not work here. – Mox Jun 19 '22 at 14:48
  • Have you considered editing the wrong file? – Martin Zeitler Jun 19 '22 at 17:19
  • @aSemy in a [`gradle.init`/ `init.gradle.kts` script](https://docs.gradle.org/current/userguide/init_scripts.html) the way you reference the plugin you want to apply is referenced by its class. So `org.springframework.boot.gradle.plugin.SpringBootPlugin` is correct and `"org.springframework.boot"` will not work. – Jmini Nov 23 '22 at 16:43

1 Answers1

1

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>()

Mox
  • 2,355
  • 2
  • 26
  • 42