This is an automated email from the ASF dual-hosted git repository.

jdaugherty pushed a commit to branch feat/forge-grails-composite
in repository https://gitbox.apache.org/repos/asf/grails-core.git

commit ba940ec4152cc8e262599f3c573654b4a352eaed
Author: James Daugherty <[email protected]>
AuthorDate: Wed Oct 7 10:14:12 2026 -0400

    Honour grails.native2ascii in a plugin's build script
    
    GrailsPluginGradlePlugin registered a whenTaskAdded hook while being 
applied, which realized every
    task, processResources among them, before the build script had run; 
grails.native2ascii set in a
    plugin's build script was therefore ignored and its message bundles were 
escaped regardless. The
    hook is a configureEach now, and a TestKit spec builds a plugin that 
switches the escaping off.
---
 .../plugin/core/GrailsPluginGradlePlugin.groovy    | 11 +++---
 ...GrailsPluginGradlePluginNative2AsciiSpec.groovy | 43 ++++++++++++++++++++++
 .../plugin-native2ascii-off/build.gradle           |  8 ++++
 .../plugin-native2ascii-off/gradle.properties      |  1 +
 .../grails-app/conf/application.yml                |  0
 .../plugin-native2ascii-off/settings.gradle        |  1 +
 .../resources/templates/messages_ru.properties     | 19 ++++++++++
 7 files changed, 78 insertions(+), 5 deletions(-)

diff --git 
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy
 
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy
index a015d0dadd..082deb7623 100644
--- 
a/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy
+++ 
b/grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePlugin.groovy
@@ -199,11 +199,12 @@ class GrailsPluginGradlePlugin extends GrailsGradlePlugin 
{
             it.classpath += sourceSets.ast.output
         }
 
-        taskContainer.whenTaskAdded {
-            if (it.name == 'compileWebappGroovyPages') {
-                it.configure {
-                    it.dependsOn(copyAstClasses)
-                }
+        // configureEach, not whenTaskAdded: the eager hook realizes every 
registered task at this point,
+        // processResources among them, and the resource processing then reads 
the grails extension
+        // before the build script has configured it (native2ascii, for one)
+        taskContainer.configureEach { Task task ->
+            if (task.name == 'compileWebappGroovyPages') {
+                task.dependsOn(copyAstClasses)
             }
         }
 
diff --git 
a/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePluginNative2AsciiSpec.groovy
 
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePluginNative2AsciiSpec.groovy
new file mode 100644
index 0000000000..364c29c9df
--- /dev/null
+++ 
b/grails-gradle/plugins/src/test/groovy/org/grails/gradle/plugin/core/GrailsPluginGradlePluginNative2AsciiSpec.groovy
@@ -0,0 +1,43 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    https://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.grails.gradle.plugin.core
+
+import org.gradle.testkit.runner.GradleRunner
+
+/**
+ * The resource processing of a plugin project reads the grails extension when 
the task is configured, so
+ * the extension must not be read before the build script has run. The plugin 
once realized every task
+ * while it was applied, and {@code native2ascii = false} in the build script 
was read too late.
+ */
+class GrailsPluginGradlePluginNative2AsciiSpec extends GradleSpecification {
+
+    def "native2ascii = false keeps a plugin's resource bundles as written"() {
+        given:
+        GradleRunner runner = 
setupTestResourceProject('plugin-native2ascii-off')
+
+        when:
+        def result = executeTask('processResources')
+
+        then:
+        assertTaskSuccess('processResources', result)
+        new File(runner.projectDir, 
'build/resources/main/templates/messages_ru.properties')
+                .getText('UTF-8')
+                .contains('welcome.title=Добро пожаловать в Grails')
+    }
+}
diff --git 
a/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/build.gradle
 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/build.gradle
new file mode 100644
index 0000000000..f79cea2f65
--- /dev/null
+++ 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/build.gradle
@@ -0,0 +1,8 @@
+plugins {
+    id 'org.apache.grails.gradle.grails-plugin'
+}
+
+// A plugin shipping message bundles as templates: they must reach the jar as 
written, not escaped
+grails {
+    native2ascii = false
+}
diff --git 
a/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/gradle.properties
 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/gradle.properties
new file mode 100644
index 0000000000..35c332fb87
--- /dev/null
+++ 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/gradle.properties
@@ -0,0 +1 @@
+grailsVersion=__PROJECT_VERSION__
diff --git 
a/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/grails-app/conf/application.yml
 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/grails-app/conf/application.yml
new file mode 100644
index 0000000000..e69de29bb2
diff --git 
a/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/settings.gradle
 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/settings.gradle
new file mode 100644
index 0000000000..01e37b7a7c
--- /dev/null
+++ 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'test-plugin-native2ascii'
diff --git 
a/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/src/main/resources/templates/messages_ru.properties
 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/src/main/resources/templates/messages_ru.properties
new file mode 100644
index 0000000000..73e1f4baf4
--- /dev/null
+++ 
b/grails-gradle/plugins/src/test/resources/test-projects/plugin-native2ascii-off/src/main/resources/templates/messages_ru.properties
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+welcome.title=Добро пожаловать в Grails

Reply via email to