Maven: Ensure Java to Java Version Compatibility

My current challenge is to ensure that the given Java project runs in Java (JRE) from version 6 to version 9. Is there a way to do this with Maven?

I am assuming the maven-compilter-plugin setup is part of this. If it will

<source>1.6</source>

      

to ensure that higher version features are not used? How about <target>

?

And which Java version should Maven work with? Java 9?

animal-sniffer-maven-plugin also looks interesting but not sure how it fits here. It's also tricky, because Java 6 is not really a minimal API, as AFAIK has some Java 9 classes (like some of the sun and com.sun packages).

What else? Has anyone done this already?

+3


source to share


1 answer


Some notes about this (maybe not quite the answer):

First, the animal-sniffer-maven-plugin plugin can check if your code is only using code from JDK 6 (API), which is the lowest part you should check (or other JDK versions). Also, you need to check if the project has a dependency on the jar that contains the byte code does not require any more JDK 6 based code.

<target>/<source>

will not provide such things. They only make sure that the resulting jar file (class file format) will work with at least JRE 6, but do not guarantee that it will also run on JRE 9.



If you need to run JRE 9, your project must have a module-info.java file.

Also, in your project is used com.sun.*

, you have a lot to do, since as far as I remember most or all of them were declared as deprecated / or for com.sun.*

only internal and not part of the public API (If you will be running on Mac with JDK, these classes don't exist) for a very long time (see here ).

You can take a look at Maven Core because we have to make sure Maven is running on JRE 9 as well ... (We're using JDK 9 EA Package to test this). There we are using animal-sniffer-maven-plugin etc. to make sure this works.

+3


source







All Articles