-
The problem
Maven automatically switches jdK5 when packing and compiling.
Idea opens a new project and packages it via Maven, indicating the JDK5 environment!
It’s tempting to wonder if the new project submodule doesn’t specify a JDK version. So the operation as shown below.
Idea sometimes defaults to using the built-in JDK11 when opening new projects. It just needs to be modified here.
But it did not take effect today, so I wonder if it is caused by changing maven’s setting file. Because this project is relatively independent, the Setting file only adds the Aliyun repository agent.
Here, I switch back to the setting file used by the original company project, and there are many things configured. It’s working fine again.
At this time, the two setting files are compared to exclude the warehouse, mapping and other configurations, and there is still one environment configuration that may be affected.
<profile> < ID > JDK-1.8 </ ID > <activation> <activeByDefault>true</activeByDefault> < JDK >1.8</ JDK > </activation> Piler < properties > < maven.com. Source > 1.8 < / maven.com piler source > < maven.com piler. Target > 1.8 < / maven.com piler. Target > The < maven.compiler.com pilerVersion > 1.8 < / maven.compiler.com pilerVersion > < / properties > < / profile >Copy the code
If you are familiar with spring multi-environment configuration, you can configure multiple environments in poM files, such as: development, test, pre-release, release, etc. Or configure multiple POM files and control incoming POM files during packaging. I won’t go into that.
This configuration can also be added in the POM file, which will add an environment to the MAVEN administration window of IDEA.
Add configuration, after testing, it is ok.
However, I don’t like it very much. If it is configured in setting, it means that it is effective for all projects using the same configuration file, which is very ugly. Ocd nightmare.
Therefore, I recommend several more:
Method 1: Specify the compiled JDK version in the current Maven project POM file.
Piler < properties > < maven.com. Source > 1.8 < / maven.com piler source > < maven.com piler. Target > 1.8 < / maven.com piler. Target > </properties>Copy the code
Option 2: Use the Maven-Compiler-plugin to specify the JDK version compiled by the current project
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>Copy the code
Method 3: For the Springboot project. Just specify the Java version. This configuration is added by default if you use SpringBoot’s official initialization project tool, so this problem has rarely been encountered before.
. < the properties > < Java version > 1.8 < / Java version > < / properties >Copy the code