This is an automated email from the ASF dual-hosted git repository. jdaugherty pushed a commit to branch feature/exploded in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit 5572554591e8d997f0bca08dca5d3ea694c39b34 Author: James Daugherty <[email protected]> AuthorDate: Tue Sep 16 15:32:34 2025 -0400 feature - prevent applying the grails application & plugin gradle plugins to the same gradle project --- grails-doc/src/en/guide/upgrading/upgrading60x.adoc | 8 ++++++++ .../org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/grails-doc/src/en/guide/upgrading/upgrading60x.adoc b/grails-doc/src/en/guide/upgrading/upgrading60x.adoc index 2d938df3c4..57ccd1435e 100644 --- a/grails-doc/src/en/guide/upgrading/upgrading60x.adoc +++ b/grails-doc/src/en/guide/upgrading/upgrading60x.adoc @@ -484,3 +484,11 @@ You will need to change it to `jcache` and add the Ehcache dependency as follows Alternatively, you can define the hibernate-ehcache dependency explicitly and adjust it to exclude `hibernate-core` and add the `jboss-transaction-api_1.3_spec` see link:upgrading.html#_12_5_hibernate_ehcache[Hibernate-ehcache] +===== 12.20 A Grails project cannot be both a plugin & an Application + +In previous versions of Grails, it was possible to apply both the `grails-plugin` and `grails-web` Gradle plugins in `build.gradle`. +This would force the project to be both a Grails Plugin and a Grails Application. +This scenario is not supported and can lead to unexpected behavior due to the AST transforms. + +Starting with Grails 7, a validation error will trigger if both a Grails Application Gradle Plugin & a Grails Plugin Gradle Plugin are configured in `build.gradle` for the same Gradle Project. + diff --git a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy index 212c7dfd48..8dcbce4a63 100644 --- a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy +++ b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy @@ -97,6 +97,13 @@ class GrailsGradlePlugin extends GroovyPlugin { } void apply(Project project) { + // validate that only an app or a plugin is registered, and never both + OnlyOneGrailsPlugin marker = (OnlyOneGrailsPlugin) project.getExtensions().findByName(OnlyOneGrailsPlugin.class.name) + if (marker) { + throw new GradleException("Project ${project.name} cannot be both a Grails application and a Grails plugin. Previously applied plugin: ${marker.pluginClassname}. Cannot apply: ${getClass().name}") + } + project.getExtensions().add(OnlyOneGrailsPlugin.class.name, new OnlyOneGrailsPlugin(pluginClassname: getClass().name)) + // reset the environment to ensure it is resolved again for each invocation Environment.reset() @@ -905,4 +912,9 @@ class GrailsGradlePlugin extends GroovyPlugin { } fileCollection } + + @CompileStatic + private static final class OnlyOneGrailsPlugin { + String pluginClassname + } }
