Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Wed Front-end Technology how to obtain and configure Maven plug-in

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you wed front-end technology Maven plug-in how to obtain and configure, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Acquisition and configuration of Maven plug-in

Maven only provides a unified abstract definition and management of the project construction process. As for who does each stage, Maven does not implement it itself, but leaves it to the corresponding plug-in. This is what plug-ins do.

For example, maven-compile-plugin can complete the task of compiling Java source code during the compile phase.

But from the plug-in itself, a plug-in can achieve multiple stages of the life cycle tasks, such as maven-dependency-plugin can achieve more than a dozen functions: analyze the project dependency function; list the project dependency tree; analyze the source of dependency and so on.

To facilitate the execution of a function of the plug-in, each function of the plug-in is called a target. In this way, you can achieve which stage, which plug-in to execute, and which goal to achieve. For example, "dependency:analyze" represents the analysis goals of maven-dependency-plugin, and "dependency:tree" indicates that maven-dependency-plugin lists dependent goals.

Binding of plug-ins to the lifecycle phase

The role and goal of the plug-in were described earlier, but the ultimate goal is to integrate the functionality of the plug-in into the relevant phases of the Maven life cycle so that the plug-in is automatically invoked to complete the specified tasks when Maven builds the project.

How do you bind the Maven lifecycle to the plug-in implementation to accomplish the actual build task?

For example, the compile goal of the maven-compile-plugin plug-in can complete the compilation task, and the compile phase of the default life cycle of Maven is defined to achieve source code compilation.

So how do users bind the compile goal of the maven-compile-plugin plug-in to the compile phase of the default lifecycle so that the plug-in's compile goal can be automatically executed when the Maven build project is in the compile phase?

There are two ways to bind the lifecycle phase to the plug-in goal: built-in binding and custom binding.

1. Built-in binding

In order to make it easy for users to use Maven, with little or no configuration, you need to build the project with Maven. After Maven is installed, it automatically binds many plug-ins for the main phase of the lifecycle.

When the user executes a phase of the life cycle through a command or graphical interface, the corresponding plug-in goals are executed automatically to complete the task.

The maven-clean-plugin plug-in has a target called clean, which removes the output directory generated when the project is built. The clean goal of maven-clean-plugin is bound by default in the clean phase of the clean lifecycle. That is, when mvn clean is executed, Maven automatically invokes maven-clean-plugin 's clean target during the clean phase, deleting the built output directory.

Similarly, the maven-site-plugin plug-in has two goals: the site goal, which is used to generate the project site, and the deploy goal, which is used to publish the generated site to the site server. By default, Maven binds the site target to the site phase of the site lifecycle, and the deploy target to the site-deploy phase of the site lifecycle.

The default life cycle is more complex, not only when there are so many stages, but also when Java can be packed into different packages (jar, war, ear, etc.). Different packages are bound differently at different stages.

Of course, you can also view the binding of phases and plug-in targets at the command prompt by running the Maven command. For example, type Maven compile in the CMD command line window and you can see the log shown in figure 1.

According to the log, you can see that the default-resources phase is bound to the "maven-resources-plugin:2.6:resources" target; the default-compile phase is bound to the "maven-compile-plugin:2.3.2:compile" target.

two。 Custom binding

In addition to the Maven built-in binding, you can also specify a target for binding a plug-in at a certain stage. This allows Maven to perform more tasks when building the project. For example, sometimes users want to package the source code as a jar package when building a project (you can choose to install src.jar when installing JDK, so you can learn the source code of JDKAPI).

For such tasks, Maven does not have built-in binding to the lifecycle phase. So this needs to be configured by the user. There is a jar-no-forkmub in maven-source-plugin that can type the main code in the project into a jar file. This allows you to bind the goal to a specified phase of the default life cycle, such as the verify phase.

These are all the contents of the article "how to get and configure the Maven plug-in for wed front-end technology". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report