|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import org.gradle.api.Project |
| 21 | +import org.gradle.process.JavaForkOptions |
| 22 | + |
| 23 | +/** |
| 24 | + * Extract the scala version from polaris spark project, and points the build directory to a sub-dir |
| 25 | + * that uses scala version as name. The polaris spark project name is in format of |
| 26 | + * <project>-<sparkVersion>_<scalaVersion>, for example: polaris-spark-3.5_2.12. |
| 27 | + */ |
| 28 | +fun Project.getAndUseScalaVersionForProject(): String { |
| 29 | + val sparkScala = project.name.split("-").last().split("_") |
| 30 | + |
| 31 | + val scalaVersion = sparkScala[1] |
| 32 | + |
| 33 | + // direct the build to build/<scalaVersion> to avoid potential collision problem |
| 34 | + project.layout.buildDirectory.set(layout.buildDirectory.dir(scalaVersion).get()) |
| 35 | + |
| 36 | + return scalaVersion |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Adds the JPMS options required for Spark to run on Java 17, taken from the |
| 41 | + * `DEFAULT_MODULE_OPTIONS` constant in `org.apache.spark.launcher.JavaModuleOptions`. |
| 42 | + */ |
| 43 | +fun JavaForkOptions.addSparkJvmOptions() { |
| 44 | + jvmArgs = |
| 45 | + (jvmArgs ?: emptyList()) + |
| 46 | + listOf( |
| 47 | + // Spark 3.3+ |
| 48 | + "-XX:+IgnoreUnrecognizedVMOptions", |
| 49 | + "--add-opens=java.base/java.lang=ALL-UNNAMED", |
| 50 | + "--add-opens=java.base/java.lang.invoke=ALL-UNNAMED", |
| 51 | + "--add-opens=java.base/java.lang.reflect=ALL-UNNAMED", |
| 52 | + "--add-opens=java.base/java.io=ALL-UNNAMED", |
| 53 | + "--add-opens=java.base/java.net=ALL-UNNAMED", |
| 54 | + "--add-opens=java.base/java.nio=ALL-UNNAMED", |
| 55 | + "--add-opens=java.base/java.util=ALL-UNNAMED", |
| 56 | + "--add-opens=java.base/java.util.concurrent=ALL-UNNAMED", |
| 57 | + "--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED", |
| 58 | + "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED", |
| 59 | + "--add-opens=java.base/sun.nio.cs=ALL-UNNAMED", |
| 60 | + "--add-opens=java.base/sun.security.action=ALL-UNNAMED", |
| 61 | + "--add-opens=java.base/sun.util.calendar=ALL-UNNAMED", |
| 62 | + "--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED", |
| 63 | + // Spark 3.4+ |
| 64 | + "-Djdk.reflect.useDirectMethodHandle=false", |
| 65 | + ) |
| 66 | +} |
0 commit comments