maven在settings.xml和pom.xml中指定jdk版本编译的方法,
分享于 点击 25972 次 点评:173
maven在settings.xml和pom.xml中指定jdk版本编译的方法,
目录
- Maven 在 settings.xml 中指定jdk版本
- 方法一, 直接写死, 例如指定jdk21
- 引用属性变量,只在一个地方修设值jdk版本
- Maven 在 pom.xml 中指定jdk版本
- 总结
maven的settings.xm和pom.xml都可以通过 maven.compiler.source , maven.compiler.target 这两个属性值来指定jdk版本
maven.compiler.source
maven.compiler.target
maven.compiler.source
maven.compiler.target
在pom.xml中的位置
<project> <properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> </properties> </project>
在settings.xml中的位置
<settings> <profiles> <profile> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <maven.compiler.source>21</maven.compiler.source> <maven.compiler.target>21</maven.compiler.target> <!-- JRE System Liblary 的版本和这句相同 --> </properties> </profile> </profiles> </settings>
在spring项目中, 用java.version
来统一设置
maven的settings.xm和pom.xml也可以通过设定 maven-compiler-plugin 这个插件来指定jdk版本
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.9.6</version> <configuration> <source>21</source> <target>21</target> </configuration> </plugin>
在pom.xml中的位置
<project> ... <build> ... <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.9.6</version> <configuration> <source>21</source> <target>21</target> </configuration> </plugin> </plugins> ... </build> ... </project>
在settings.xml中的位置 , 好像用不了
<settings> ... <profiles> <profile> <id>profile-maven-compiler-plugin</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.9.6</version> <configuration> <source>17</source> <target>17</target> </configuration> </plugin> </plugins> </build> </profile> </profiles> ... </settings>
Maven 在 settings.xml 中指定jdk版本
settings.xml 中的属性写在 setting
用户点评