Build project using JDK 11 (#1733)

* Support build on both JDK 1.8 & 11, check for publishing under JDK 11
* Up the Robolectric version to support JDK11.
  According to https://github.com/robolectric/robolectric/issues/4085, by 4.0.2
it should support JDK11.
  Tests do pass after setting the version to 4.0.2, but they fail for every version released after that up to 4.3.1.
  It is unclear what causes this. I commit this to check how it works on the build agents, as some comments in the issue imply that on MacOS this version, too, does not work with JDK11.
* Fix fully qualified names in stacktraces in tests:
  - With move to JDK11, the `park` method changed its fully qualified name.
* Add new sanitazing to verification of stacktraces:
  - Now stacktraces have additional substrings, separated by a slash:
    java-base/java.util.lang
  - They are stripped away.
  - Also, the placement of tabs has changed, and so the tabs are also completely removed.
* Refactor `verifyStackTrace`
  - It used to wrap the only loop where something happened in two other loops that did nothing. Now, only the innermost loop is left.
* Use a separate JavaFx dependency.
* Improve error handling for JavaFX initialization
  - Now, the JavaFX initialization may fail with an exception in case something went wrong.
  - The driver for this change was that the initialization started hanging in headless environments with transition to JDK 11.
  - Before, the initialization logic had a flaw. If a call to one API
failed, another API would be attempted. However, this approach is
problematic: if the first call failed with an exception for some
reason, it would leave JavaFX in a broken state where a flag would
imply that the system is being initialized. Subsequent calls would
then proceed to wait forever for the initialization to complete.
  - Now, exceptions are checked more carefully, ensuring that we only
fall back to the internal API in case the public one is unavailable
and not failed for some valid reason. This differentiation also
allows to more boldly rethrow exceptions upwards, being more or
less confident that these are relevant to the user.
* Additionally test JavaFX integration with JDK8

Co-authored-by: Dmitry Khalanskiy <dmitry.khalanskiy@jetbrains.com>
Co-authored-by: Roman Elizarov <elizarov@gmail.com>
diff --git a/build.gradle b/build.gradle
index e020937..273fd00 100644
--- a/build.gradle
+++ b/build.gradle
@@ -78,6 +78,7 @@
         classpath "org.jetbrains.kotlinx:atomicfu-gradle-plugin:$atomicfu_version"
         classpath "org.jetbrains.kotlinx:kotlinx-knit:$knit_version"
         classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
+        classpath "org.openjfx:javafx-plugin:$javafx_plugin_version"
         classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
 
         // JMH plugins
@@ -269,8 +270,26 @@
 // Report Kotlin compiler version when building project
 println("Using Kotlin compiler version: $org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION")
 
+// --------------- Publish only from under JDK11+ ---------------
+task checkJdkForPublish {
+    doFirst {
+        String javaVersion = System.properties["java.version"]
+        int i = javaVersion.indexOf('.')
+        int javaVersionMajor =  (i < 0 ? javaVersion : javaVersion.substring(0, i)).toInteger()
+        if (javaVersionMajor < 11) {
+            throw new GradleException("Project can be build for publishing only under JDK 11+, but found ${javaVersion}")
+        }
+    }
+}
+
 // --------------- Configure sub-projects that are published ---------------
-task deploy(dependsOn: getTasksByName("publish", true) + getTasksByName("publishNpm", true))
+def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm", true)
+
+publishTasks.each {
+    it.dependsOn checkJdkForPublish
+}
+
+task deploy(dependsOn: publishTasks)
 
 apply plugin: 'base'