Compiling to older versions of Java using Maven

Posted on

Hello everyone, my code is written in Java 17. I was wondering if there is a way to compile to older versions of Java (8 and later).
I am using this compiler to run some code – https://www.interviewbit.com/online-java-compiler/
I also asked this question on quora and many people online suggest I should use something like this:

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

However, when I do this I get the following problem:

Caused by: java.lang.IllegalStateException: warning: source release 17 requires target release 17

Using release with maven-compiler-plugin instead didn’t help either.
What I don’t understand is that if target and source must be exactly the same, then why do we need both?
I’m using Maven 3.8.3, by the way.

Leave a Reply

Your email address will not be published.