THRIFT-5581: use gradle 7 for java/kotlin (#2601)

* upgrade gradle version to 7.4
* migrate from `maven` plugin to `maven-publish` plugin as required for Gradle 7
* add guard to ktfmt, since it can't run with JDK 8

Co-authored-by: Christopher Tubbs <ctubbsii@apache.org>
diff --git a/lib/kotlin/cross-test-server/build.gradle.kts b/lib/kotlin/cross-test-server/build.gradle.kts
index 508b29d..eda1ebd 100644
--- a/lib/kotlin/cross-test-server/build.gradle.kts
+++ b/lib/kotlin/cross-test-server/build.gradle.kts
@@ -19,9 +19,9 @@
 
 plugins {
     kotlin("jvm")
-    id("com.ncorti.ktfmt.gradle")
     java
     application
+    id("com.ncorti.ktfmt.gradle")
 }
 
 repositories {
@@ -60,8 +60,10 @@
         mainClass.set("org.apache.thrift.test.TestServerKt")
     }
 
-    ktfmt {
-        kotlinLangStyle()
+    if (JavaVersion.current().isJava11Compatible) {
+        ktfmt {
+            kotlinLangStyle()
+        }
     }
 
     task<Exec>("compileThrift") {
diff --git a/lib/kotlin/cross-test-server/src/main/kotlin/org/apache/thrift/test/TestServer.kt b/lib/kotlin/cross-test-server/src/main/kotlin/org/apache/thrift/test/TestServer.kt
index d9c0c86..566e53d 100644
--- a/lib/kotlin/cross-test-server/src/main/kotlin/org/apache/thrift/test/TestServer.kt
+++ b/lib/kotlin/cross-test-server/src/main/kotlin/org/apache/thrift/test/TestServer.kt
@@ -167,17 +167,18 @@
 
 class TestServerCommand : CliktCommand() {
     private val port: Int by option(help = "The cross test port to connect to").int().default(9090)
-    private val protocolType: ProtocolType by option("--protocol", help = "Protocol type")
-        .enum<ProtocolType> { it.key }
-        .default(ProtocolType.Binary)
-    private val transportType: TransportType by option("--transport", help = "Transport type")
-        .enum<TransportType> { it.key }
-        .default(TransportType.Buffered)
-    private val serverType: ServerType by option("--server-type")
-        .enum<ServerType> { it.key }
-        .default(ServerType.NonBlocking)
-    private val useSSL: Boolean by option("--ssl", help = "Use SSL for encrypted transport")
-        .flag(default = false)
+    private val protocolType: ProtocolType by
+        option("--protocol", help = "Protocol type")
+            .enum<ProtocolType> { it.key }
+            .default(ProtocolType.Binary)
+    private val transportType: TransportType by
+        option("--transport", help = "Transport type")
+            .enum<TransportType> { it.key }
+            .default(TransportType.Buffered)
+    private val serverType: ServerType by
+        option("--server-type").enum<ServerType> { it.key }.default(ServerType.NonBlocking)
+    private val useSSL: Boolean by
+        option("--ssl", help = "Use SSL for encrypted transport").flag(default = false)
     private val stringLimit: Long by option("--string-limit").long().default(-1)
     private val containerLimit: Long by option("--container-limit").long().default(-1)