目前部分项目使用
JDK8
,部分项目使用JDK19
因此,环境变量中还是保持JDK8
,只需要下载JDK19
免安装版本,通过配置IDEA
就可以完成本地开发。
# 一、IDEA 环境设置
【1】通过快捷键CTRL + SHIFT + ALT + S
或者File->Project Structure...
设置SDK
和Language level
,不存在JDK19
时可通过Edit
添加

【2】设置下方的Modules
中的Sources
模块和Dependencies
模块


【3】设置下方的Platform Setting
中的SDKs
模块

【4】设置File->Settings...
中的Build,Excepotion,Deployment
下的Builder Tools->Maven->Runner
模块

【5】设置File->Settings...
中的Build,Excepotion,Deployment
下的Compiler->Java Compiler
模块

【6】如果使用了Tomcat
点击Edit Configurations...
后,设置JRE
模块


【7】设置完成后通过Maven
插件进行编译,因为通过控制台执行mvn
命令时使用的是本地环境变量中配置的JDK
版本,而Maven
插件使用的是IDEA
中配置的JDK
版本。

# 二、POM依赖修改
在项目父模块的pom.xml
中添加如下plugin
<properties>
<maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
<java.version>19</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>--enable-preview</compilerArgument>
<compilerVersion>${java.version}</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<argLine>
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.base/sun.reflect.annotation=ALL-UNNAMED
--add-opens java.base/java.math=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/sun.util.calendar=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED
--add-opens java.base/java.net=ALL-UNNAMED
--add-opens java.xml/com.sun.org.apache.xerces.internal.jaxp.datatype=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
后面遇到最多的就是项目包的冲突问题,依次解决就好