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/settings.gradle.kts b/lib/kotlin/settings.gradle.kts
index a6bdbbc..2eff402 100644
--- a/lib/kotlin/settings.gradle.kts
+++ b/lib/kotlin/settings.gradle.kts
@@ -18,8 +18,15 @@
  */
 pluginManagement {
     plugins {
-        kotlin("jvm") version "1.5.31"
-        id("com.ncorti.ktfmt.gradle") version "0.4.0"
+        kotlin("jvm") version "1.6.10"
+        // per https://github.com/cortinico/ktfmt-gradle/tags the latest version requires Gradle 7.4 which in turn
+        // requires Java 11, failing the xenial build which is still on Java 8. Here we both configure the plugin
+        // but with different version, and only enabling ktfmt configure for Java 11+, to make the legacy build happy
+        if (JavaVersion.current().isJava11Compatible) {
+            id("com.ncorti.ktfmt.gradle") version "0.8.0"
+        } else {
+            id("com.ncorti.ktfmt.gradle") version "0.5.0"
+        }
     }
 }