Skip to content

Commit

Permalink
KAFKA-17739 Clean up build.gradle to adopt the minimum Java version a…
Browse files Browse the repository at this point in the history
…s 11 (apache#17426)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
  • Loading branch information
frankvicky authored Oct 10, 2024
1 parent f1aa3a5 commit 9b62c86
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 38 deletions.
26 changes: 3 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ plugins {

ext {
gradleVersion = versions.gradle
minJavaVersion = 8
minJavaVersion = 11
buildVersionFileName = "kafka-version.properties"

defaultMaxHeapSize = "2g"
Expand Down Expand Up @@ -184,12 +184,7 @@ allprojects {
options.addStringOption('Xdoclint:none', '-quiet')
// Javadoc warnings should fail the build in JDK 15+ https://bugs.openjdk.org/browse/JDK-8200363
options.addBooleanOption('Werror', JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_15))

// The URL structure was changed to include the locale after Java 8
if (JavaVersion.current().isJava11Compatible())
options.links "https://docs.oracle.com/en/java/javase/${JavaVersion.current().majorVersion}/docs/api/"
else
options.links "https://docs.oracle.com/javase/8/docs/api/"
options.links "https://docs.oracle.com/en/java/javase/${JavaVersion.current().majorVersion}/docs/api/"
}

clean {
Expand Down Expand Up @@ -309,25 +304,10 @@ subprojects {
options.compilerArgs << "-Xlint:-serial"
options.compilerArgs << "-Xlint:-try"
options.compilerArgs << "-Werror"

// --release is the recommended way to select the target release, but it's only supported in Java 9 so we also
// set --source and --target via `sourceCompatibility` and `targetCompatibility` a couple of lines below
if (JavaVersion.current().isJava9Compatible())
options.release = minJavaVersion
// --source/--target 8 is deprecated in Java 20, suppress warning until Java 8 support is dropped in Kafka 4.0
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_20))
options.compilerArgs << "-Xlint:-options"

options.release = minJavaVersion
addParametersForTests(name, options)
}

java {
// We should only set this if Java version is < 9 (--release is recommended for >= 9), but the Scala plugin for IntelliJ sets
// `-target` incorrectly if this is unset
sourceCompatibility = minJavaVersion
targetCompatibility = minJavaVersion
}

if (shouldPublish) {

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class OAuthBearerSaslClientProvider extends Provider {

@SuppressWarnings("this-escape")
protected OAuthBearerSaslClientProvider() {
super("SASL/OAUTHBEARER Client Provider", 1.0, "SASL/OAUTHBEARER Client Provider for Kafka");
super("SASL/OAUTHBEARER Client Provider", "1.0", "SASL/OAUTHBEARER Client Provider for Kafka");
put("SaslClientFactory." + OAuthBearerLoginModule.OAUTHBEARER_MECHANISM,
OAuthBearerSaslClientFactory.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class OAuthBearerSaslServerProvider extends Provider {

@SuppressWarnings("this-escape")
protected OAuthBearerSaslServerProvider() {
super("SASL/OAUTHBEARER Server Provider", 1.0, "SASL/OAUTHBEARER Server Provider for Kafka");
super("SASL/OAUTHBEARER Server Provider", "1.0", "SASL/OAUTHBEARER Server Provider for Kafka");
put("SaslServerFactory." + OAuthBearerLoginModule.OAUTHBEARER_MECHANISM,
OAuthBearerSaslServerFactory.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PlainSaslServerProvider extends Provider {

@SuppressWarnings("this-escape")
protected PlainSaslServerProvider() {
super("Simple SASL/PLAIN Server Provider", 1.0, "Simple SASL/PLAIN Server Provider for Kafka");
super("Simple SASL/PLAIN Server Provider", "1.0", "Simple SASL/PLAIN Server Provider for Kafka");
put("SaslServerFactory." + PlainSaslServer.PLAIN_MECHANISM, PlainSaslServerFactory.class.getName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ScramSaslClientProvider extends Provider {

@SuppressWarnings("this-escape")
protected ScramSaslClientProvider() {
super("SASL/SCRAM Client Provider", 1.0, "SASL/SCRAM Client Provider for Kafka");
super("SASL/SCRAM Client Provider", "1.0", "SASL/SCRAM Client Provider for Kafka");
for (ScramMechanism mechanism : ScramMechanism.values())
put("SaslClientFactory." + mechanism.mechanismName(), ScramSaslClientFactory.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ScramSaslServerProvider extends Provider {

@SuppressWarnings("this-escape")
protected ScramSaslServerProvider() {
super("SASL/SCRAM Server Provider", 1.0, "SASL/SCRAM Server Provider for Kafka");
super("SASL/SCRAM Server Provider", "1.0", "SASL/SCRAM Server Provider for Kafka");
for (ScramMechanism mechanism : ScramMechanism.values())
put("SaslServerFactory." + mechanism.mechanismName(), ScramSaslServerFactory.class.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
public class TestPlainSaslServerProvider extends Provider {

public TestPlainSaslServerProvider() {
this("TestPlainSaslServerProvider", 0.1, "test plain sasl server provider");
this("TestPlainSaslServerProvider", "0.1", "test plain sasl server provider");
}

protected TestPlainSaslServerProvider(String name, double version, String info) {
protected TestPlainSaslServerProvider(String name, String version, String info) {
super(name, version, info);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class TestProvider extends Provider {
private static final String TRUST_MANAGER_FACTORY = String.format("TrustManagerFactory.%s", TestTrustManagerFactory.ALGORITHM);

public TestProvider() {
this("TestProvider", 0.1, "provider for test cases");
this("TestProvider", "0.1", "provider for test cases");
}

@SuppressWarnings("this-escape")
protected TestProvider(String name, double version, String info) {
protected TestProvider(String name, String version, String info) {
super(name, version, info);
super.put(KEY_MANAGER_FACTORY, TestKeyManagerFactory.class.getName());
super.put(TRUST_MANAGER_FACTORY, TestTrustManagerFactory.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
public class TestScramSaslServerProvider extends Provider {

public TestScramSaslServerProvider() {
this("TestScramSaslServerProvider", 0.1, "test scram sasl server provider");
this("TestScramSaslServerProvider", "0.1", "test scram sasl server provider");
}

protected TestScramSaslServerProvider(String name, double version, String info) {
protected TestScramSaslServerProvider(String name, String version, String info) {
super(name, version, info);
}

Expand Down
5 changes: 5 additions & 0 deletions gradle/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -547,5 +547,10 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
</Or>
<Bug pattern="RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT"/>
</Match>
<Match>
<!-- Suppress warning about using static DateFormat in a multithreaded context -->
<Class name="org.apache.kafka.tools.ReplicaVerificationTool$ReplicaBuffer"/>
<Bug pattern="STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE"/>
</Match>

</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
Expand Down Expand Up @@ -254,9 +255,10 @@ public void configure(Map<String, ?> configs) {

if (transfererClass != null) {
try {
transferer = (Transferer) getClass().getClassLoader().loadClass(transfererClass).newInstance();

} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ClassCastException e) {
transferer = (Transferer) getClass().getClassLoader().loadClass(transfererClass)
.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | ClassCastException |
InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(format("Cannot create transferer from class '%s'", transfererClass), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -74,7 +75,10 @@ private <T> void verify(T val1) throws Exception {
Class<T> clazz = (Class<T>) val1.getClass();
T val2 = JsonUtil.JSON_SERDE.readValue(bytes, clazz);
for (Field field : clazz.getDeclaredFields()) {
boolean wasAccessible = field.isAccessible();
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
boolean wasAccessible = field.canAccess(val2);
field.setAccessible(true);
assertNotNull(field.get(val2), "Field " + field + " was null.");
field.setAccessible(wasAccessible);
Expand Down

0 comments on commit 9b62c86

Please sign in to comment.