1

I have a Maven project and in the pom there is nothing like:

<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

If I run mvn clean compile and check the bytecode with javap -classpath ../project/target/classes/ -verbose com.xxx.Class I see

minor version: 0
major version: 55

which corresponds to Java 11.

I found the bug ticket MCOMPILER-376 that states that the default version should be 1.7. This is also clearly stated in the plugin documentation:

Also note that at present the default source setting is 1.7 and the default target setting is 1.7, independently of the JDK you run Maven with. You are highly encouraged to change these defaults by setting source and target as described in Setting the -source and -target of the Java Compiler.

I also found a very detailed Stack overflow answer but it did not help me finding the information I am looking for.

I would like to understand how did the Maven compiler plugin knew that it had to use Java 11.

Carlo
  • 1,686
  • 3
  • 29
  • 43
  • Any chance your project has parent? Hard to tell without the full POM. – Pavel Horal Apr 08 '22 at 13:59
  • There is also the option to use `11` ... It's likely that it is defined in a parent? – khmarbaise Apr 08 '22 at 14:00
  • 1
    @PavelHoral Oh, why didn't I thought about it. I guess you already answered my question then. My pom has the spring-boot-starter as a parent and I assume that in its pom I will find the configuration I am looking for. – Carlo Apr 08 '22 at 14:04
  • I can see java version being set to 1.8 in spring-boot-starter-parent https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.6.6/spring-boot-starter-parent-2.6.6.pom. Not sure where 11 is coming from though... but it should be fairly easy to find. – Pavel Horal Apr 08 '22 at 14:26
  • That depends on the version of spring boot you are using... – khmarbaise Apr 08 '22 at 15:38

0 Answers0