Revisiting initscripts and plugins


(Schalk Cronjé) #1

Since Gradle 3.x release have come out, I thought I’d tackle and old issue again: Apply plugins from an initialisation script. I created a simple plugin and published it to mavenLocal(). Then set up the initscript

initscript {
    repositories {
        mavenLocal()
    }

    dependencies {
        classpath 'foo:bar:0.1-SNAPSHOT'
    }
}



rootProject {
    apply plugin : foo.bar.MyPlugin
}

So that actually worked if I applied my the full class name. If I did

rootProject {
  apply plugin : 'foo.bar'
}

instead (using the id) it did not work. (Issue 1).

Next step was to make my plugin depend on another plugin external.plugin.on.portal, which can be subtitiuted for any know n plugin identifier. Thus my plugin code could now contain something like

class MyPlugin implements Plugin<Project> {
  void apply( Project project ) {
    project.apply plugin : 'external.plugin.on.portal'
  }
}

Using the original init script that worked, I tried my rebuilt plugin, my it will fail to apply the external plugin becasue it cannot find it. (Issue 2).

OK I thought this is simple, just add

initscript {
  repositories {
    jcenter()
    maven {
            url "https://plugins.gradle.org/m2/"
    }
 }
}

but that did not work either. So seeingly there are still some issues with initscript, that might still not be fixed.

Any thing I should be doing differently or are these still bugs?