Skip to content

Commit 3473c9f

Browse files
authored
Configure Gradle toolchains with correct JDK (#3918)
Resolves #3831 Signed-off-by: Dariusz Jędrzejczyk <[email protected]>
1 parent ba1b387 commit 3473c9f

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

buildSrc/src/main/java/io/reactor/gradle/JavaConventions.java

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020-2021 VMware Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2020-2024 VMware Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,12 +20,12 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23-
import org.gradle.api.JavaVersion;
2423
import org.gradle.api.Plugin;
2524
import org.gradle.api.Project;
2625
import org.gradle.api.plugins.JavaPlugin;
2726
import org.gradle.api.plugins.JavaPluginExtension;
2827
import org.gradle.api.tasks.compile.JavaCompile;
28+
import org.gradle.jvm.toolchain.JavaLanguageVersion;
2929

3030
/**
3131
* @author Simon Baslé
@@ -38,15 +38,22 @@ public void apply(Project project) {
3838
}
3939

4040
private void applyJavaConvention(Project project) {
41-
JavaPluginExtension java = project.getExtensions().getByType(JavaPluginExtension.class);
42-
java.setSourceCompatibility(JavaVersion.VERSION_1_8);
43-
java.setTargetCompatibility(JavaVersion.VERSION_1_8);
41+
project.getExtensions().getByType(JavaPluginExtension.class).toolchain(toolchain -> {
42+
toolchain.getLanguageVersion().set(JavaLanguageVersion.of(8));
43+
});
4444

4545
project.getTasks()
4646
.withType(JavaCompile.class)
4747
.forEach(compileTask -> {
4848
compileTask.getOptions().setEncoding("UTF-8");
49-
compileTask.getOptions().setCompilerArgs(Arrays.asList(
49+
50+
List<String> compilerArgs = new ArrayList<>(
51+
compileTask.getOptions().getCompilerArgs());
52+
53+
if (compileTask.getName().endsWith("TestJava")) {
54+
compilerArgs.add("-parameters");
55+
}
56+
compilerArgs.addAll(Arrays.asList(
5057
"-Xlint:-varargs", // intentionally disabled
5158
"-Xlint:cast",
5259
"-Xlint:classfile",
@@ -67,17 +74,8 @@ private void applyJavaConvention(Project project) {
6774
"-Xmaxerrs", "500",
6875
"-Xmaxwarns", "1000"
6976
));
70-
});
7177

72-
if (JavaVersion.current().isJava8Compatible()) {
73-
project.getTasks().withType(JavaCompile.class, t -> {
74-
if (t.getName().endsWith("TestJava")) {
75-
List<String> args = new ArrayList<>(t.getOptions().getCompilerArgs());
76-
args.add("-parameters");
77-
t.getOptions().setCompilerArgs(args);
78-
}
78+
compileTask.getOptions().setCompilerArgs(compilerArgs);
7979
});
80-
}
81-
8280
}
8381
}

gradle/javadoc.gradle

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2021 VMware Inc. or its affiliates, All Rights Reserved.
2+
* Copyright (c) 2011-2024 VMware Inc. or its affiliates, All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,5 @@ javadoc {
4848
maxMemory = "1024m"
4949
destinationDir = project.layout.buildDirectory.dir("docs/javadoc").get().asFile
5050

51-
if (JavaVersion.current().isJava8Compatible()) {
52-
options.addStringOption("Xdoclint:none", "-quiet")
53-
}
51+
options.addStringOption("Xdoclint:none", "-quiet")
5452
}

0 commit comments

Comments
 (0)