You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2020/07/20 09:45:09 UTC
[lucene-solr] 01/01: Switch to public JVM lookup API. Add support
for using alt jvm with all javac tasks.
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch jira/LUCENE-9312
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
commit 8b5eaaca46e8d824802efd01bb0d484664de44f2
Author: Dawid Weiss <dw...@apache.org>
AuthorDate: Mon Jul 20 11:44:50 2020 +0200
Switch to public JVM lookup API. Add support for using alt jvm with all javac tasks.
---
gradle/testing/runtime-jvm-support.gradle | 47 ++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 14 deletions(-)
diff --git a/gradle/testing/runtime-jvm-support.gradle b/gradle/testing/runtime-jvm-support.gradle
index ce48b56..26eb370 100644
--- a/gradle/testing/runtime-jvm-support.gradle
+++ b/gradle/testing/runtime-jvm-support.gradle
@@ -18,35 +18,54 @@
// 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
+JavaInstallationRegistry registry = extensions.getByType(JavaInstallationRegistry)
-def jvmForTests = {
+JavaInstallation currentJvm = registry.installationForCurrentVirtualMachine.get()
+
+JavaInstallation altJvm = {
def runtimeJavaHome = propertyOrDefault("runtime.java.home", System.getenv('RUNTIME_JAVA_HOME'))
if (!runtimeJavaHome) {
- return Jvm.current()
+ return currentJvm
} else {
- return Jvm.forHome(file(runtimeJavaHome))
+ return registry.installationForDirectory(
+ layout.projectDirectory.dir(runtimeJavaHome)).get()
}
}()
-def jvmGradle = Jvm.current()
-def differentTestJvm = (jvmGradle.javaHome.canonicalPath != jvmForTests.javaHome.canonicalPath)
+if (!currentJvm.javaExecutable.equals(altJvm.javaExecutable)) {
+ // Set up java toolchain tasks to use the alternative Java.
+ // This is a related Gradle issue for the future:
+ // https://github.com/gradle/gradle/issues/1652
-// Set up tasks to use the alternative Java.
-if (differentTestJvm) {
configure(rootProject) {
- task testJvmWarning() {
+ task altJvmWarning() {
doFirst {
- logger.warn("This Java will be used for running tests: ${jvmForTests.javaExecutable}")
+ logger.warn("""NOTE: Alternative java toolchain will be used for compilation and tests:
+ Project will use Java ${altJvm.javaVersion} from: ${altJvm.installationDirectory}
+ Gradle runs with Java ${currentJvm.javaVersion} from: ${currentJvm.installationDirectory}
+""")
}
}
}
- // Set up test tasks to use the alternative JVM.
+ // Set up toolchain-dependent tasks to use the alternative JVM.
allprojects {
+ // Any tests
tasks.withType(Test) {
- dependsOn ":testJvmWarning"
- executable = jvmForTests.javaExecutable
+ dependsOn ":altJvmWarning"
+ executable = altJvm.javaExecutable
+ }
+
+ // Any javac compilation tasks
+ tasks.withType(JavaCompile) {
+ options.fork = true
+ options.forkOptions.javaHome = altJvm.installationDirectory.asFile
}
+
+ // Look at Elasticsearch's code; there are caveats concerning build artifact caching
+ // (we don't use it at the moment, but who knows).
+ // TODO: Any jar calls?
+ // TODO: Any javadoc calls?
}
-}
\ No newline at end of file
+
+}