Search code examples
gradlebuild.gradlegradle-plugingradlewspring-boot-gradle-plugin

Artifact id resolved wrong


I am new to gradle and I am facing a weird problem while I’m trying to add a plugin in gradle. I know that we have to specify an if and version in plugin body for a gradle build, but I tried to add a plugin with some id and version. My question is..how does a gradle build know which artifact id to choose if there are multiple artifacts under same group id? I know that this might be a lame question...but I’m pretty new to gradle and I’d like to know your input.


Solution

  • Are you trying to apply the spring-boot-plugin?

    If so, does the project you're trying to apply the plugin to have a buildscript block like this:

    buildscript {
      repositories {
        maven {
          url "https://plugins.gradle.org/m2/"
        }
      }
      dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:2.0.4.RELEASE"
      }
    }
    
    apply plugin: "org.springframework.boot"
    

    or a plugin closure:

    plugins {
      id "org.springframework.boot" version "2.0.4.RELEASE"
    }
    

    With a buildscript block, Gradle knows where to find the plugin because I've specified a repository for it to go look for it. After resolving the dependency path it finds and downloads the plugin, then puts it on the classpath for use in build.gradle files. It then only needs to get applied, i.e. apply plugin: ....

    With the plugins closure, things are a bit trickier. Plugins are published under a unique id, which is looked up and gradle resolves the specified version. I'm not too terribly knowledgeable about how this is done, but here, new plugin mechanism , describes some differences between buildscript {} apply plugin: ... and plugins {}.