Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compiling down a version - eclipse, maven

I was recently stung by some code making it through our deployment cycle without throwing any compile errors when it should have (we thought)...

The code in question being using the new static method Integer.compare which is since Java 1.7.

The server environment is run on Java 1.6. While our development environments have Java 1.7 installed.

Our assumption was that setting the project preferences to JavaSE-1.6 compliance would at least give us compile warnings on the code in question, however no warning or error is visible in eclipse.

Project > properties > java compiler > JDK Compliance > Use compliance from execution environment 'JavaSE-1.6' on the java build path

Secondarily to that, we use maven to compile the final deployment. The pom is clearly directed to comply with the 1.6 compiler:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <optimize>true</optimize>
    </configuration>
</plugin>

However the maven build runs successfully with the problem code.

How can I tell both maven and eclipse to fail when code will not work in an earlier Jvm than it is being compiled by?

Thanks, Paul.

like image 359
pstanton Avatar asked Mar 19 '12 01:03

pstanton


1 Answers

Use the maven animal sniffer plugin to tell you when you use APIs that aren't backward compatible. I'm also told that Java 1.7 has a feature for this, but I have no personal experience with it.

like image 89
bmargulies Avatar answered Sep 30 '22 18:09

bmargulies