|
26 | 26 | import java.util.List;
|
27 | 27 | import java.util.Map;
|
28 | 28 | import java.util.TreeMap;
|
| 29 | +import java.util.function.Consumer; |
29 | 30 |
|
30 | 31 | import io.spring.javaformat.gradle.FormatTask;
|
31 | 32 | import io.spring.javaformat.gradle.SpringJavaFormatPlugin;
|
@@ -127,14 +128,22 @@ private void applyJavaConventions(Project project) {
|
127 | 128 | project.setProperty("sourceCompatibility", "1.8");
|
128 | 129 | project.getTasks().withType(JavaCompile.class, (compile) -> {
|
129 | 130 | compile.getOptions().setEncoding("UTF-8");
|
| 131 | + withOptionalBuildJavaHome(project, (javaHome) -> { |
| 132 | + compile.getOptions().setFork(true); |
| 133 | + compile.getOptions().getForkOptions().setJavaHome(new File(javaHome)); |
| 134 | + compile.getOptions().getForkOptions().setExecutable(javaHome + "/bin/javac"); |
| 135 | + }); |
130 | 136 | List<String> args = compile.getOptions().getCompilerArgs();
|
131 | 137 | if (!args.contains("-parameters")) {
|
132 | 138 | args.add("-parameters");
|
133 | 139 | }
|
134 | 140 | });
|
135 |
| - project.getTasks().withType(Javadoc.class, |
136 |
| - (javadoc) -> javadoc.getOptions().source("1.8").encoding("UTF-8")); |
| 141 | + project.getTasks().withType(Javadoc.class, (javadoc) -> { |
| 142 | + javadoc.getOptions().source("1.8").encoding("UTF-8"); |
| 143 | + withOptionalBuildJavaHome(project, (javaHome) -> javadoc.setExecutable(javaHome + "/bin/javadoc")); |
| 144 | + }); |
137 | 145 | project.getTasks().withType(Test.class, (test) -> {
|
| 146 | + withOptionalBuildJavaHome(project, (javaHome) -> test.setExecutable(javaHome + "/bin/java")); |
138 | 147 | test.useJUnitPlatform();
|
139 | 148 | test.setMaxHeapSize("1024M");
|
140 | 149 | });
|
@@ -192,6 +201,13 @@ private File createLegalFile(File source, String filename) {
|
192 | 201 | return legalFile;
|
193 | 202 | }
|
194 | 203 |
|
| 204 | + private void withOptionalBuildJavaHome(Project project, Consumer<String> consumer) { |
| 205 | + String buildJavaHome = (String) project.findProperty("buildJavaHome"); |
| 206 | + if (buildJavaHome != null && !buildJavaHome.isEmpty()) { |
| 207 | + consumer.accept(buildJavaHome); |
| 208 | + } |
| 209 | + } |
| 210 | + |
195 | 211 | private void configureSpringJavaFormat(Project project) {
|
196 | 212 | project.getPlugins().apply(SpringJavaFormatPlugin.class);
|
197 | 213 | project.getTasks().withType(FormatTask.class, (formatTask) -> formatTask.setEncoding("UTF-8"));
|
|
0 commit comments