| /* |
| * 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 |
| * |
| * http://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. |
| */ |
| |
| // This adds support for compiling and testing against a different Java runtime. |
| // This is the only way to build against JVMs not yet supported by Gradle itself. |
| |
| import org.gradle.internal.jvm.Jvm |
| |
| def jvmForTests = { |
| def runtimeJavaHome = propertyOrDefault("runtime.java.home", System.getenv('RUNTIME_JAVA_HOME')) |
| if (!runtimeJavaHome) { |
| return Jvm.current() |
| } else { |
| return Jvm.forHome(file(runtimeJavaHome)) |
| } |
| }() |
| def jvmGradle = Jvm.current() |
| |
| def differentTestJvm = (jvmGradle.javaHome.canonicalPath != jvmForTests.javaHome.canonicalPath) |
| |
| // Set up tasks to use the alternative Java. |
| if (differentTestJvm) { |
| configure(rootProject) { |
| task testJvmWarning() { |
| doFirst { |
| logger.warn("This Java will be used for running tests: ${jvmForTests.javaExecutable}") |
| } |
| } |
| } |
| |
| // Set up test tasks to use the alternative JVM. |
| allprojects { |
| tasks.withType(Test) { |
| dependsOn ":testJvmWarning" |
| executable = jvmForTests.javaExecutable |
| } |
| } |
| } |