Tools and Resource Center

Help developers work more efficiently and provide tools and resources around the full developer lifecycle

Developer.aliyun.com/tool?spm=a1…

Plug-in article

1. Specify the compiled version and source file encoding method of Java in Maven

Maven’s default build is JDK1.5, and there are many times when code fails and the cause is unknown, most likely because the JDK version is not configured. Like the question I once had: Define global exception handling class inheritance HandlerInterceptorAdapter, preHandle method with @ Override has been an error, it opens at HandlerInterceptorAdapter source code, is clearly with this method, later found the JDK version of the problem, After setting it up as follows, the error is resolved.

1 1.The first way

Specified in the project’s pom.xml file, but this method is only valid for the project, as shown in the red box below, set to JDK1.8.

<build> <plugins> <! Plugins </groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> < Configuration > <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> </build>Copy the code

1. 2 The second way

In the conf folder of the Maven installation directory, modify settings. XML file and add the following Settings to the Profiles node, as shown in the image below, to JDK1.8. This method is valid for all Maven projects.

<profile> < ID >JDK1.8</ ID > <activation> <activeByDefault>true</activeByDefault> </activation> <properties> Piler < maven.com. Source > 1.8 < / maven.com piler. Source > < maven.com piler. Target > 1.8 < / maven.com piler. Target > <encoding>UTF-8</encoding> </properties> </profile>Copy the code

2. Maven multi-module package, JAR package and WAR output to the specified folder

Sample Maven multi-module project structure

Add the outputDirectory of spring-boot-Maven-plugin to the PARENT project POM

<properties> <! -- Properties define jar package save path --> <project.jar.output.directory>D:\JT\java\workspace\webvr-end\deploy</project.jar.output.directory> </properties> <build>  <pluginManagement> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <! -- File name and output path --> <configuration> <! ${project.artifactid}-1.0.5</finalName> ${project.artifactid}-1.0.5</finalName> <outputDirectory>${project.jar.output.directory}</outputDirectory> </configuration> </plugin> <! Plugins </groupId> <artifactId> Maven-surefire-plugin </artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </pluginManagement> </build>Copy the code

The output effect

Under the parent project, execute

mvn clean package -Dmaven.test.skip=true
Copy the code

MVN command

1. Common commands

perform The command Parameter interpretation
Maven forces update dependencies mvn clean install -e -U -e Indicates detailed exceptions. -u indicates forcible update

2. Description of command parameters

The command parameter note
mvn -v –version Displays the version information.
mvn -V –show-version Displays the version information and executes other Maven targets.
mvn -h –help Displays help information.
mvn -e –errors Controls Maven’s log level and generates execution error messages.
mvn -X –debug Controls the log level of Maven and generates execution debugging information.
mvn -q –quiet Controls Maven’s log level, displaying only errors;
mvn -Pxxx Activate the profile whose ID is XXX (if there are multiple profiles, separate them with commas).
mvn -Dxxx=yyy Specify Java global properties;
mvn -o –offline Works in offline mode and does not rely on network update.
mvn -N –non-recursive only execute commands in the current project module, do not build submodules;
mvn -pl –module_name executes commands on the specified module;
mvn -ff — Fail-fast Exits when build fails;
mvn -fn — Fail-never Builds never fail, regardless of the outcome of the project;
mvn -fae –fail-at-end only affects build results, allowing unaffected builds to continue;
mvn -C –strict-checksums If the checkcodes do not match, the build fails.
mvn -c — Loose-checksums If the checksums code is mismatched, an alarm is generated.
mvn -U Force snapshot type plug-ins or dependencies to be updated (otherwise Maven only updates snapshot dependencies once a day);
mvn -npu –no-plugin-s does not update any relevant registered plug-ins (use this option to make Maven exhibit stable behavior based on all plug-in versions currently available in the local repository);
mvn -cpu — Check -plugin-updates enforce the latest check for any related plugin (even if the Maven plugin version is specified in the project POM);
mvn -up — a synonym for update-plugins [mvn-cpu];
mvn -B — Batch-mode Runs in non-interactive (batch) mode (in this mode, when Mven needs input, it does not stop to accept input from the user, but uses reasonable defaults);
mvn -f –file Forces the use of the standby POM file;
mvn -s — Settings Alternate path of the user configuration file.
mvn -gs –global-settings Alternate path for the global configuration file.
mvn -emp –encrypt-master-password Encrypts the master security password and stores it in the Maven Settings file.
mvn -ep –encrypt-password Encrypts the server password and stores it in the Maven Settings file.
mvn -npr –no-plugin-registry does not use the configuration in ~/.m2/plugin-registry.

This article from: developer.aliyun.com/article/788…