jamesfredley commented on code in PR #15403:
URL: https://github.com/apache/grails-core/pull/15403#discussion_r2825060410


##########
grails-gradle/plugins/src/test/java/org/grails/gradle/plugin/core/GrailsGradlePluginToolchainTest.java:
##########
@@ -0,0 +1,399 @@
+/*
+ *  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.BuildResult;
+import org.gradle.testkit.runner.GradleRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests that {@link GrailsGradlePlugin} propagates the project's Java 
toolchain
+ * to JavaExec tasks via {@code javaLauncher.convention()}.
+ *
+ * <p>Without the fix, JavaExec tasks spawned by Grails (dbm-* migration
+ * commands, console, shell, application context commands) use the JDK
+ * running Gradle instead of the project's configured toolchain. This
+ * causes {@code UnsupportedClassVersionError} when the project targets
+ * a different JDK version than the one running Gradle.</p>
+ *
+ * <p>NOTE: Cannot use Spock here because grails-gradle-tasks transitively
+ * pulls {@code org.apache.groovy:groovy:4.0.30} which conflicts with
+ * Gradle's built-in {@code org.codehaus.groovy:groovy:3.0.25}.</p>
+ *
+ * @since 7.0.8
+ */
+class GrailsGradlePluginToolchainTest {
+
+    @TempDir
+    Path projectDir;
+
+    private static final int CURRENT_JDK = Runtime.version().feature();
+    private static final String GRAILS_VERSION = resolveGrailsVersion();
+
+    /**
+     * Reads {@code projectVersion} from the root {@code gradle.properties} so 
the
+     * test stays in sync with the actual build and is not tied to a hardcoded 
version.
+     */
+    private static String resolveGrailsVersion() {
+        Properties props = new Properties();
+        try (InputStream in = GrailsGradlePluginToolchainTest.class
+                
.getClassLoader().getResourceAsStream("grails-gradle-plugins-project.properties"))
 {
+            if (in != null) {
+                props.load(in);
+                String v = props.getProperty("projectVersion");
+                if (v != null && !v.isEmpty()) return v;
+            }
+        } catch (IOException ignored) { }
+        // Fallback: read from root gradle.properties relative to working 
directory
+        try {
+            Path root = Path.of(System.getProperty("user.dir"));
+            // Walk up until we find gradle.properties with projectVersion
+            for (Path dir = root; dir != null; dir = dir.getParent()) {
+                Path gp = dir.resolve("gradle.properties");
+                if (Files.exists(gp)) {
+                    Properties rootProps = new Properties();
+                    try (var reader = Files.newBufferedReader(gp)) {
+                        rootProps.load(reader);
+                    }
+                    String v = rootProps.getProperty("projectVersion");
+                    if (v != null && !v.isEmpty()) return v;
+                }
+            }
+        } catch (IOException ignored) { }

Review Comment:
   This is no longer relevant - the entire `resolveGrailsVersion()` method and 
the Java test file have been removed. `projectVersion` is now passed as a 
system property from the Gradle test task configuration, so there's no runtime 
discovery at all.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to