jamesfredley commented on code in PR #15403: URL: https://github.com/apache/grails-core/pull/15403#discussion_r2825054332
########## 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() { Review Comment: Done. `projectVersion` and `currentJdk` are now passed as system properties from the test task configuration in `build.gradle`, and read via `System.getProperty()` in the `GradleSpecification` base class. No more runtime discovery. -- 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]
