/* * 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. */ // Produce an MR-JAR with Java 19+ foreign and vector implementations configure(project(":lucene:core")) { plugins.withType(JavaPlugin) { mrjarJavaVersions.each { jdkVersion -> sourceSets.create("main${jdkVersion}") { java { srcDirs = ["src/java${jdkVersion}"] } } configurations["main${jdkVersion}Implementation"].extendsFrom(configurations['implementation']) dependencies.add("main${jdkVersion}Implementation", sourceSets.main.output) tasks.named("compileMain${jdkVersion}Java").configure { def apijar = apijars.file("jdk${jdkVersion}.apijar") int releaseIndex = options.compilerArgs.indexOf("--release") options.compilerArgs.removeAt(releaseIndex) options.compilerArgs.removeAt(releaseIndex) options.compilerArgs += [ "-Xlint:-options", "--add-exports", "java.base/java.lang.foreign=ALL-UNNAMED", // for compilation we patch the incubator packages into java.base, this has no effect on resulting class files: "--add-exports", "java.base/jdk.incubator.vector=ALL-UNNAMED", ] options.compilerArgumentProviders.add(new CompilerArgsProvider(apiJarFile: apijar)) } } tasks.named('jar').configure { boolean needMRJAR = false; mrjarJavaVersions.each { jdkVersion -> // the sourceSet which corresponds to the minimum/base Java version // will copy its output to root of JAR, all other sourceSets will go into MR-JAR folders: boolean isBaseVersion = (jdkVersion.toString() == rootProject.minJavaVersion.toString()) into(isBaseVersion ? '' : "META-INF/versions/${jdkVersion}") { from sourceSets["main${jdkVersion}"].output } needMRJAR |= !isBaseVersion } if (needMRJAR) { manifest.attributes( 'Multi-Release': 'true' ) } } } } class CompilerArgsProvider implements CommandLineArgumentProvider { @InputFile @PathSensitive(PathSensitivity.RELATIVE) RegularFile apiJarFile @Override Iterable asArguments() { return ["--patch-module", "java.base=${apiJarFile}"] } }