Version compilation - eclipse, maven

I was recently hit by some code that did this through our deployment cycle, without throwing any compilation errors when it should (we thought) ...

The code in question uses the new static method Integer.compare , which is found with Java 1.7.

The server environment runs on Java 1.6. Although Java 1.7 is installed in our development environments.

Our assumption was that setting project preferences to match JavaSE-1.6 would at least give us a compilation of warnings for the code in question, but eclipse doesnโ€™t show a warning or error.

Project> properties> java compiler> JDK Compliance> Use compliance from the 'JavaSE-1.6' runtime in the java build path

Secondly, we use maven to compile the final deployment. Obviously, pom will obey compiler 1.6:

 <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 succeeds with the problem code.

How can I say that both maven and eclipse fail if the code does not work in an earlier Jvm than it compiles?

Thanks, Paul.

+6
source share
2 answers

Use the sniffer plugin for animals to tell you when you use APIs that do not support backward compatibility. I am also told that Java 1.7 has a function for this, but I have no personal experience.

+2
source

Install java 1.6 into the development environment, then right-click on the project in eclipse and go to Properties-> Java Build Path. Go to the Libraries tab and remove the java 1.7 JRE, then add the java 1.6 JRE.

I am not familiar enough with maven to answer this half.

+2
source

Source: https://habr.com/ru/post/911054/


All Articles