Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of maven.compiler.source and maven.compiler.target in maven

Shulou Source: shulou.com Published: 2022-06-02 04:43:27 10月04日 Update

This article mainly shows you "how to solve the problem of maven.compiler.source and maven.compiler.target in maven". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to solve the problem of maven.compiler.source and maven.compiler.target in maven".

The pit of maven maven.compiler.source and maven.compiler.target

Recently, the product group was advised to upgrade jdk 1.7 to 1.8. Last night, the developer reported a problem, saying that after maven.compiler.source and maven.compiler.target were changed to 1.8, the compiled code was still 1.7, as follows:

You can also view the java compiled version number of the class file through javap-v ServiceImpl.class.

In the afternoon, I took the time to take a look, and sure enough, the first suspicion was that the two parameters maven.compiler.source and maven.compiler.target were unreliable.

Take a look at the JDK configured by IDE

As follows:

After automatic build, it is indeed jdk 1.7

As follows:

Replace it with J2SE-1.8

Change it to 1.6

Looking up the official maven documentation, you can see that maven.compiler.source and maven.compiler.target are only recommendations, not mandatory.

If you want to force the jdk version

You can specify the executable attribute to guarantee it, as follows:

[...] [...] Org.apache.maven.plugins maven-compiler-plugin 3.7.0 true true 1.3 [...] [...]

Problem solved.

Maven compiler error java:-source,pom setting maven.compiler.source principle

The plug-in Maven compiler Plugin we compiled is used to compile code. When we were just learning java, we used the javac command to compile .java files into .class files.

And set up

${java.version} ${java.version}

Is to specify javac-source and target options, the official website

Sometimes, the diamond operator is not supported in maven compilation error java:-source 1.5 because no compiled version is specified. Just specify the version.

The above is all the content of this article entitled "how to solve the problem of maven.compiler.source and maven.compiler.target in maven". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Compilation problem that is version content file article code learning help enforcement sure enough product principle parameter command official attribute suggestion plug-in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Huawei OPPO Reno Microsoft Apple