Maven-plug-in configuration and analysis
Plug-in configuration is to specify the predefined parameter values for the bound plug-in to further adjust the tasks executed by the plug-in target. You can configure the plug-in through the command line and POM in the form of global configuration, not all plug-in configuration can be configured through the command line.
1. Command line plug-in configuration
For example, the maven-surefire-plugin plug-in provides a maven. test. skip parameter. If the value is true, the execution test is skipped and the command line execution method is skipped:
Mvninstall-Dmaven. test. skip = true mvn install
We can compare the outputs of the two in the console and find that there is an additional test stage below:
------------------------------------------------------- T e s t s --------------------------------------------------- Runningorg. andy. items. thkinjava. string. arrayListDisplayTest [Latte, 0, Americano, 1, Latte, 2, Breve, 3, Breve, 4, Mocha, 5, Latte, 6, Americano, 7, Cappuccino, 8, Cappuccino, 9] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.046 secRunningorg. andy. items. thkinjava. string. ex7TestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 secRunning org. andy. items. thkinjava. string. immutableTestTests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 secRunningorg. andy. items. thkinjava. string. infiniteRecursionTest
2. Global configuration of the POM plug-in
When declaring a plug-in, make a global configuration for this plug-in. All later users who use this plug-in must follow this configuration, for example, specify the source file for maven-compile-plugin to compile Java 1.7:
<Plugin> <groupId> org. apache. maven. plugins </groupId> <artifactId> maven-compiler-plugin </artifactId> <version> 3.1 </version> <configuration> <source> 1.8 </source> <target> 1.8 </target> </configuration> </plugin>
The above setting will report an error because the local environment is jdk1.7, and the compilation of version 1.8 is required,
[ERROR] Failed to execute goalorg. apache. maven. plugins: maven-compiler-plugin: 3. 1: compile (default-compile) on project items-thkinjava: Fatal error compiling: I nvalid target release: 1.8-> [Help 1]
Change "1.8" to "1.7". The version can be earlier than 1.7, indicating that the version is compatible with the previous version. (Remember to use mvn clean to delete the previously compiled class before compilation ).
3. Get plug-in information
For example, you can view the parameters that can be used, usage, examples, and FAQs of the plug-in target:
Web: http://maven.apache.org/plugins/index.html
: Http://repo1.maven.org/maven2/org/apache/maven/plugins/
4. Plug-in parsing mechanism
Maven parses the correct plug-in without providing complete plug-in coordinate information through the plug-in target, which simplifies the use and configuration of the plug-in, but also makes it more difficult to locate the error source in case of problems.. Understand the parsing mechanism and the essence.
5. Plug-In repository
The plug-ins and dependencies are similar. When they are used, they will go to the local warehouse to find the plug-ins. If they cannot be found, they will go to the remote warehouse to find the plug-ins, download them to the local warehouse, and use them. the repository is a different repository. maven treats dependent repositories and plug-in repositories differently. When a plug-in cannot be found in the local repository, it will go to the plug-in repository to find the dependency repository.. The configuration of the plug-in Repository is similar to that of the dependent Repository. The Repositories and Repository used by different and dependent Repositories are used. The plug-in Repositories use pluginRepositories and pluginRepository, and maven has built-in plug-in Repository configurations. -- $ M2-HOME/lib/maven-model-builder3.2.3.jar/org/apache/maven/model/pom. in xml:
<PluginRepositories> <pluginRepository> <id> central </id> <name> CentralRepository </name> <url> https://repo.maven.apache.org/maven2 </url> <layout> default </layout> <snapshots> <enabled> false </enabled> </snapshots> <releases> <updatePolicy> never </updatePolicy> </releases> </pluginRepository> </pluginRepositories>
Similar to the dependent repository:
<Repositories> <repository> <id> central </id> <name> CentralRepository </name> <url> https://repo.maven.apache.org/maven2 </url> <layout> default </layout> <snapshots> <enabled> false </enabled> </snapshots> </repository> </repositories>
The comparison shows that the two repositories are the central repository, but if there is no plug-in repository configuration, and maven cannot find plug-ins locally, it will not find the required plug-ins in the central repository. For the sake of stability, the plug-in of the snapshot version is disabled, and the plug-ins in the local repository are never updated.
6. Default groupId of the plug-in
Configure the plug-in POM. If groupId is not configured, it indicates that it is the official maven plug-in, that is, the groupId is org. apache. maven. plugins, which saves a lot of configuration, will also make unfamiliar people confused, not recommended for use.
7. Resolution plug-in version
Maven uses metadata. xml to parse versions. Similarly, maven3 uses release instead of SNAPSHOT and latest when the plug-in does not declare versions.
8. Resolution plug-in prefix
Maven can execute commands by using the plug-in prefix: plug-in target, such as clean: clean, and execute maven-clean-plugins: clean, maven is based on a combination of **/*/plugins/maven-metadata.xml and com/your/plugins/maven-metadata.xml in your local repository, get complete plug-in information based on prefix.
Summary
Master the three sets of maven lifecycles, stages, and default plug-in targets for each stage, master the concepts of lifecycle and plug-ins, configure plug-ins, plug-ins, custom bindings, and configure plug-ins. know where the default plug-in repository is configured and what it is, configure the plug-in repository, and master the connection between the plug-in and dependency.
Maven-plug-in configuration and analysis