Skip to content

Commit

Permalink
Compatibility fix with JDK9+
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Feb 15, 2019
1 parent d2d79c8 commit 980c450
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
language: java
jdk:
- openjdk8
- openjdk11
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
script:
- ./gradlew --info
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ internal val isRunningInsideGradle: Boolean get() {
val jars: List<URL> = classLoader.urLs.toList()
return (jars.any { it.toString().contains("gradle-worker.jar") })
}
// JDK 9+ uses AppClassLoader
val methodGetUrls = classLoader::class.java.getDeclaredMethod("getURLs")
val jars = methodGetUrls.invoke(classLoader) as Array<URL>
return (jars.any { it.toString().contains("gradle-worker.jar") })
// JDK 9+ uses AppClassLoader which doesn't provide a list of URLs for us.
// we need to check in a different way whether there is `gradle-worker.jar` on the classpath.
// we know that it contains the worker/org/gradle/api/JavaVersion.class
val workerJar = classLoader.getResource("worker/org/gradle/api/JavaVersion.class")
return workerJar.toString().contains("gradle-worker.jar")
} catch (t: Throwable) {
// give up, just pretend that we're inside of Gradle
t.printStackTrace()
t.printStackTrace() // to see these stacktraces run Gradle with --info
return true
}
}
Expand Down

0 comments on commit 980c450

Please sign in to comment.