Cannot use "plugins" block inside "subprojects" block

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.

1 Like

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

2 Likes

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

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?

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"
}
4 Likes

removed, because I used the wrong forum

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.

This limitation still exists in Gradle 6.5.

@Gradle Team,

Could you please let us know when this limitation would be addressed.?