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 3c515248be4aa501f1fc126f23c05dd4f0d4a217
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          |  6 ++++++
 .../org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy  | 12 ++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/grails-doc/src/en/guide/upgrading/upgrading60x.adoc 
b/grails-doc/src/en/guide/upgrading/upgrading60x.adoc
index 2d938df3c4..7e60517372 100644
--- a/grails-doc/src/en/guide/upgrading/upgrading60x.adoc
+++ b/grails-doc/src/en/guide/upgrading/upgrading60x.adoc
@@ -484,3 +484,9 @@ 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 of these 
plugins 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
+    }
 }

Reply via email to