[hibernate-dev] Ensuring only Java 6 API is used when compiling with JDK 7
Gunnar Morling
gunnar at hibernate.org
Mon Dec 17 06:04:45 EST 2012
Hi all,
Recently Steve and I spoke on IRC about compiling code on JDK 7 but
targeting Java 6 for the built artifacts.
While setting source and target level to 1.6 makes sure that the source and
byte code are compliant with Java 6, there is still the possibility of
inadvertently using classes/methods introduced in Java 7, causing runtime
errors when executing that code on Java 6.
As I just learned, there's a tool called "Animal Sniffer" [1] which helps
to prevent this kind of error by checking a project against a given API
baseline, e.g. the Java 6 API. Using functionality not contained in that
API signature causes a build-time error.
As an example, I found out that we're using a method in HV which was
introduced only in Java 1.6.0_18, causing the code to fail on earlier Java
6 runtimes [2].
Animal Sniffer provides a Maven plug-in and an Ant task which I think
should also be usable with Gradle.
--Gunnar
[1] http://mojo.codehaus.org/animal-sniffer/
[2] https://hibernate.onjira.com/browse/HV-661
More information about the hibernate-dev
mailing list