THRIFT-5560: use JUnit 5 for all Java lib tests (#2574)

diff --git a/lib/java/gradle/environment.gradle b/lib/java/gradle/environment.gradle
index 12fee15..2f49a0d 100644
--- a/lib/java/gradle/environment.gradle
+++ b/lib/java/gradle/environment.gradle
@@ -71,7 +71,7 @@
     compile "javax.annotation:javax.annotation-api:${javaxAnnotationVersion}"
     compile "org.apache.commons:commons-lang3:3.12.0"
 
-    testCompile "junit:junit:${junitVersion}"
+    testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
     testCompile "org.mockito:mockito-all:${mockitoVersion}"
     testRuntime "org.slf4j:slf4j-log4j12:${slf4jVersion}"
 }
diff --git a/lib/java/gradle/unitTests.gradle b/lib/java/gradle/unitTests.gradle
index 10a5539..0f09aa9 100644
--- a/lib/java/gradle/unitTests.gradle
+++ b/lib/java/gradle/unitTests.gradle
@@ -68,8 +68,15 @@
     include '**/Test*.class'
     exclude '**/Test*\$*.class'
 
+    // https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle
+    useJUnitPlatform() {
+        // https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution
+        systemProperty("junit.jupiter.execution.parallel.enabled", "true")
+        systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
+        systemProperty("junit.jupiter.execution.parallel.mode.classes.default", "concurrent")
+    }
+
     maxHeapSize = '512m'
-    forkEvery = 1
 
     systemProperties = [
         'build.test': "${compileTestJava.destinationDir}",