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/java/Makefile.am b/lib/java/Makefile.am
index 1e1ee9b..1dd42a7 100644
--- a/lib/java/Makefile.am
+++ b/lib/java/Makefile.am
@@ -26,7 +26,7 @@
 		--console=plain
 
 install-exec-hook:
-	$(GRADLE) $(GRADLE_OPTS) install \
+	$(GRADLE) $(GRADLE_OPTS) publishToMavenLocal \
 		-Prelease=true \
 		-Pinstall.path=$(DESTDIR)$(JAVA_PREFIX) \
 		-Pinstall.javadoc.path=$(DESTDIR)$(docdir)/java \
@@ -51,7 +51,7 @@
 		--console=plain
 
 maven-publish:
-	$(GRADLE) $(GRADLE_OPTS) uploadArchives \
+	$(GRADLE) $(GRADLE_OPTS) publish \
 		-Prelease=true \
 		-Pthrift.version=$(PACKAGE_VERSION) \
 		--console=plain