|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
39 | 39 | import org.gradle.api.plugins.BasePlugin;
|
40 | 40 | import org.gradle.api.plugins.JavaPlugin;
|
41 | 41 | import org.gradle.api.plugins.JavaPluginConvention;
|
| 42 | +import org.gradle.api.plugins.JavaPluginExtension; |
42 | 43 | import org.gradle.api.tasks.SourceSet;
|
43 | 44 | import org.gradle.api.tasks.TaskProvider;
|
44 | 45 | import org.gradle.api.tasks.compile.JavaCompile;
|
| 46 | +import org.gradle.jvm.toolchain.JavaToolchainService; |
| 47 | +import org.gradle.jvm.toolchain.JavaToolchainSpec; |
| 48 | +import org.gradle.util.GradleVersion; |
45 | 49 |
|
46 | 50 | import org.springframework.boot.gradle.tasks.bundling.BootBuildImage;
|
47 | 51 | import org.springframework.boot.gradle.tasks.bundling.BootJar;
|
@@ -137,9 +141,22 @@ private void configureBootRunTask(Project project) {
|
137 | 141 | return Collections.emptyList();
|
138 | 142 | });
|
139 | 143 | run.conventionMapping("main", new MainClassConvention(project, run::getClasspath));
|
| 144 | + configureToolchainConvention(project, run); |
140 | 145 | });
|
141 | 146 | }
|
142 | 147 |
|
| 148 | + private void configureToolchainConvention(Project project, BootRun run) { |
| 149 | + if (isGradle67OrLater()) { |
| 150 | + JavaToolchainSpec toolchain = project.getExtensions().getByType(JavaPluginExtension.class).getToolchain(); |
| 151 | + JavaToolchainService toolchainService = project.getExtensions().getByType(JavaToolchainService.class); |
| 152 | + run.getJavaLauncher().convention(toolchainService.launcherFor(toolchain)); |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + private boolean isGradle67OrLater() { |
| 157 | + return GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.7")) >= 0; |
| 158 | + } |
| 159 | + |
143 | 160 | private JavaPluginConvention javaPluginConvention(Project project) {
|
144 | 161 | return project.getConvention().getPlugin(JavaPluginConvention.class);
|
145 | 162 | }
|
|
0 commit comments