Using idea and maven to configure the compiled version of jdk

Confusion of jdk compiled version

Due to the pursuit of version stability and legacy of old projects, we often have to switch the compiled version of JDK at any time, which is a stranger to the latest jdk11. We have been criticized for forgetting to use the idea switch of different versions of JDK for a long time

Several ways to configure jdk with idea and maven

  • The first maven global setting configuration
<profile>
	<id>jdk-1.8</id>
	<activation>
		<activeByDefault>true</activeByDefault>
		<jdk>1.8</jdk>
	</activation>
	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
	</properties>
</profile>
<profile>
	<id>jdk-1.7</id>
	<activation>
		<activeByDefault>false</activeByDefault>
		<jdk>1.7</jdk>
	</activation>
	<properties>
		<maven.compiler.source>1.7</maven.compiler.source>
		<maven.compiler.target>1.7</maven.compiler.target>
		<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
	</properties>
</profile>
  • The second configuration of pom in maven project
<properties>
	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	<java.version>1.8</java.version>
</properties>

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
		<source>${java.version}</source>
		<target>${java.version}</target>
	</configuration>
</plugin>

  • File - > setting - > java compiler in idea
  • File - > project structure - > modules in idea

The summary is as follows

  • The first one is global configuration, and profile switching is convenient
  • The second is the configuration in the current project. Other projects are not affected, and the priority is higher than the profile

Tags: Programming Maven JDK Java Apache

Posted on Wed, 06 May 2020 07:49:02 -0700 by banjax