Cannot use "plugins" block inside "subprojects" block


(Dierk König) #1

In the FregeFX project, I use the frege plugin from the plugin portal.
I have to apply the plugin to both subprojects (fregefx and examples) but not the root project as the root is not a frege project itself and thus doesn’t build with the frege plugin applied.

As of now, I have to duplicate the “plugins” block in both subprojects since I cannot put it in the “subprojects” block of root.

I would find it more consistent if plugin application from portal would also play nicely with subproject blocks.


(Mark Worger) #2

you can, but you have to do it as follows:

subprojects { subproject ->
    subproject.apply plugin: 'plugin_name'
}

i.e. the ‘subproject.apply’ is the important bit


(Dierk König) #3

Thanks, Mark, but unfortunately that approach seems to make no difference at all.


(Mark Worger) #4

That’s odd, I’m working on a project now that is using that format to apply plugins to subprojects, so it should be working.

What is the error that you’re getting?


(Mark Vieira) #5

You are correct, the plugins { } block cannot be used within a subprojects { } block. This is a known limitation. If you want to apply the plugin to all subprojects you’ll have to use the alternate syntax.

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.org.frege-lang:frege-gradle-plugin:0.6"
  }
}

subprojects {
   apply plugin: "org.frege-lang"
}

(Horst Scheruga) #6

removed, because I used the wrong forum


(Sean Fitts) #7

Is it known when this limitation will be addressed (or is there an issue we can track). It would be nice to switch to the new approach, but we can’t since we use multi-projects.