What version of Java should I use for developing my MOJO Maven Plugin?

fabien7474 :

I am currently implementing a new Maven Plugin and I would like to use Java 11 for compilation and execution.

However, I would like my Maven plugin to be used by most of our projects. Some of them are running in Java 8, some in Java 11.

Is it mandatory to use Java 8 in my Maven Plugin if I want it to be included in other project ? Is there a way to implement it in Java 11 and make it available for Java 8 project ?

Robert Scholte :

As quite often: it depends. And with Maven Java is used at different levels, so this requires a bit of explanation:

Are you going to use Java 9+ specific features/APIs?

If not, you can build your project with Java 11, but you need to add <release>8</release> to the maven-compiler-plugin to ensure the code is Java 8 compatible.

If you do plan to use Java 9+ features/APIs, add <release>11</release> to the maven-compiler-plugin. Now you require your users that they run Maven with at least Java 11 (which is not a problem, even Maven 3.0 runs fine with Java 14-ea).

Even though Maven runs on Java 11, your users can still create Java 8 compatible projects (just like the "if not, ..." from the first bullet), but most are used to run and build with Java 8.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=357004&siteId=1