1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-21 22:02:06 +01:00

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.
This commit is contained in:
Florian Schmaus 2020-04-24 10:04:30 +02:00
parent e79710840b
commit f61ecb65e7
2 changed files with 18 additions and 11 deletions

View file

@ -4,8 +4,7 @@ android:
components:
- android-19
jdk:
- oraclejdk8
- openjdk9
- openjdk8
- openjdk11
before_cache:

View file

@ -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[]