Skip to content

Commit

Permalink
Check configured JavaLauncher when determining version of the JVM
Browse files Browse the repository at this point in the history
Previously, bootRun assumed that the Java version of the JVM that would
run the application would be the same as the Java version of the JVM
that is running the build. This assumption does not hold true when
Gradle's toolchain support is used to configure tasks that fork a new
JVM to use a version other than that being used by Gradle itself.

This commit updates the BootRun task to query the JavaLauncher property
when determining the version of Java on which the application will be
run. Toolchain support and the JavaLauncher property are new in Gradle
6.7. To support earlier versions of Gradle, NoSuchMethodError is caught
we continue as if no JavaLauncher has been configured and use the local
JVM's Java version.

Fixes gh-24512
  • Loading branch information
wilkinsona committed Jan 11, 2021
1 parent 5ad4d62 commit 064de4e
Showing 1 changed file with 12 additions and 1 deletion.
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,12 @@
import java.lang.reflect.Method;

import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetOutput;
import org.gradle.jvm.toolchain.JavaLauncher;

/**
* Custom {@link JavaExec} task for running a Spring Boot application.
Expand Down Expand Up @@ -84,6 +86,15 @@ public void exec() {
}

private boolean isJava13OrLater() {
try {
Property<JavaLauncher> javaLauncher = this.getJavaLauncher();
if (javaLauncher.isPresent()) {
return javaLauncher.get().getMetadata().getLanguageVersion().asInt() >= 13;
}
}
catch (NoSuchMethodError ex) {
// Continue
}
for (Method method : String.class.getMethods()) {
if (method.getName().equals("stripIndent")) {
return true;
Expand Down

0 comments on commit 064de4e

Please sign in to comment.