From f61ecb65e7a7d31c5ea1485ac7067e91f2237114 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Fri, 24 Apr 2020 10:04:30 +0200 Subject: [PATCH] Make java(c|doc) use --release when available In order to truely stay Java 8 compatible, declaring a source and target compatiblity is not sufficient. Source compatiblity means that the input, i.e. the code written in Java is compatible with that particular version of the Java Language Specification (JLS). And target compatibitliy means that the produced Java bytecode is compatible with that particular version of the Java Virtual Machine Specificiation (JVMS). But there is actually a third dimension: the runtime library (rt.jar). If signatures of methods change over java releases within the runtime library, then the produced bytecode, may contain calls to methods that do not exist with that exact same signature in older java versions. For example the family of Buffer subclasses changed the return value of certain functions, for example flip() to not return Buffer, but the concrete type of the current instance, e.g. CharBuffer. If we compile now with a newer JDK, where the return type is CharBuffer and not Buffer, then executing on an older JDK, where the return type is Buffer, then we get java.lang.NoSuchMethodError(s) thrown at us. Fixes SMACK-651. --- .travis.yml | 3 +-- build.gradle | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index ad03d90f1..10f7b90f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,8 +4,7 @@ android: components: - android-19 jdk: - - oraclejdk8 - - openjdk9 + - openjdk8 - openjdk11 before_cache: diff --git a/build.gradle b/build.gradle index 5ced307b4..76cf80d61 100644 --- a/build.gradle +++ b/build.gradle @@ -122,9 +122,11 @@ allprojects { // Default to true useSonatype = true } + javaCompatilibity = JavaVersion.VERSION_1_8 + javaMajor = javaCompatilibity.getMajorVersion() } group = 'org.igniterealtime.smack' - sourceCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = javaCompatilibity targetCompatibility = sourceCompatibility version = shortVersion if (isSnapshot) { @@ -244,7 +246,19 @@ allprojects { options.addStringOption('Xwerror', '-quiet') } } - tasks.withType(Javadoc) { + + if (JavaVersion.current().isJava9Compatible()) { + tasks.withType(Javadoc) { + options.addStringOption('-release', javaMajor) + } + tasks.withType(JavaCompile) { + options.compilerArgs.addAll([ + '--release', javaMajor, + ]) + } + } + +tasks.withType(Javadoc) { options.charSet = "UTF-8" options.encoding = 'UTF-8' } @@ -290,16 +304,10 @@ task javadocAll(type: Javadoc) { project.sourceSets.main.compileClasspath}) classpath += files(androidBootClasspath) options { - // Add source compatiblitiy statement to work around bug in JDK 11 - // See - // - https://bugs.openjdk.java.net/browse/JDK-8217177 - // - http://hg.openjdk.java.net/jdk/jdk/rev/8ce4083fc831 - // - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=920020 - source = sourceCompatibility linkSource = true use = true links = [ - "https://docs.oracle.com/javase/${sourceCompatibility.getMajorVersion()}/docs/api/", + "https://docs.oracle.com/javase/${javaMajor}/docs/api/", "https://jxmpp.org/releases/$jxmppVersion/javadoc/", "https://minidns.org/releases/$miniDnsVersion/javadoc/", ] as String[]