1. maven-compiler-plugin for code compilation
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.0</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin>
The compiled version can also be set like this:
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties>
2. Use the compiler that comes with eclipse to compile. If there is a new feature of jdk1.7 (generic), an error will be reported. Add the plexus-compiler-eclipse build for processing.
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <compilerId>eclipse</compilerId> </configuration> <dependencies> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-compiler-eclipse</artifactId> <version>2.2</version> </dependency> </dependencies> </plugin>
3. Another solution to the above problems: When Eclipse compiles the code (ie clean), it uses its own JDT (Java Development Tools), while Maven uses the javac in JAVA_HOME by default, and javac is compared to the JDT inspection mechanism. That said, it is more strict, so Eclipse can compile and pass, and Maven compilation will report an error result. Solution: Click Eclipse -> Project -> Clean... Use JDT to compile the source code to the target folder, and then use mvn package to package it directly (do not add clean).
4. Configuration explanation
<source>: The development version used by the source code
<target>: The compiled version of the target class file to be generated