Java – is there any practical reasoning to force the build of the JDK version?

There is a maven enforcer plugin that can force the build to run only on a specific JDK version

I wonder if there is any practical reasoning? We have built a configuration to specify the source and target versions As far as I know, this should be more than enough because Java is backward compatible For example, its appearance in gradle:

compileJava   {
  sourceCompatibility = '1.8'
  targetCompatibility = '1.8'
}

This is what it looks like in Maven:

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

If you need an exact JDK version for any reason – please write it down

UPD. The question is more whether there is any actual difference if you compile java source / target version 8 projects with JDK 8, 9, 10 or 11

Solution

The main reason for this may be some better optimizations in the newer JDK compiler Therefore, even if the target bytecode level is the same as the old compiler, the target bytecode itself may be improved

According to Brian Goetz, this pulls its weight:

Editor: sorry! The tweet quoted is about compiling with a source below the target (e.g. - source 8 - target 11), so it is different from what OP asks Nevertheless, even if the target remains unchanged, perhaps newer compilers can produce better bytecode

PS. as basil told me, let me mention the javac -- release flag of JDK 9, which can prevent using the newer JDK API when insisting on using the older language level

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>