Gradle, "sourceCompatibility" vs "targetCompatibility"?
Be careful when you use these; we've been bitten by people making assumptions.
Just because you use sourceCompability (or targetCompatibility) of 1.5 doesn't mean you can always compile your code with JDK 1.6 and expect it to work under JDK 1.5. The issue is the available libraries.
If your code happens to call some method that is only available in JDK 1.6 it will still compile with the various Compatibility options for the target VM. But when you run it, it will fail because the offending method is not present (you'll get a MethodNotFoundException or ClassNotFoundException).
For this reason, I always compare the Compatibility setting to the actual Java version I'm building under. If they don't match, I fail the build.
targetCompatibility
and sourceCompatibility
maps to -target release
and -source release
in javac. Source is basically the source language level and target is the level of the bytecode that is generated.
More details can be found in the javac the cross compilation section.