Ten years of JAVA moving bricks - maven foundation

definition

Maven is a project management and build tool used to help developers automate the building, testing, and deployment of Java projects. It provides functions such as a standardized project structure, dependency management, build life cycle and plug-in system, making the project management and construction process easier and more reliable. Maven uses an XML-based configuration file (pom.xml) to define project dependencies, build goals, and other configuration information. Through Maven, developers can more easily manage project dependencies, build and release processes.

Maven's architecture is based on plugins and lifecycles. It consists of the core engine, plugins and lifecycle.

The core engine is the core part of Maven, responsible for parsing project configuration files (pom.xml), managing dependencies, and executing build tasks. It provides a set of APIs and a command line interface for developers to interact with Maven.

Plugins are Maven extension modules that provide additional functionality and tasks. Plugins can be used to compile code, run tests, package projects, deploy applications, and more. Maven's plug-in mechanism allows developers to add or customize plug-ins as needed to meet the needs of specific projects.

A lifecycle defines a set of predefined build phases and associated plugin goals. Maven's life cycle includes stages such as clean, validate, compile, test, package, install, and deploy. Each phase has a default plugin target associated with it, and developers can execute different phases and targets as needed to complete the project's build process.

Lifecycle command usage

clean command
The "clean" command in Maven is used to clean a project by removing generated build artifacts. It deletes the target directory and all files and folders generated during the build process, such as compiled classes, packaged JARs, test reports, etc.

To use the "clean" command in Maven, open a terminal or command prompt, navigate to the root directory of the Maven project (where the pom.xml file resides), and run the following command:

 mvn clean 

The validate command
The "validate" phase in Maven is responsible for validating the project structure and configuration. It checks that the project's configuration files (such as pom.xml) are valid and consistent.

 mvn validate 

The "compile" command
The "compile" command in Maven is used to compile the Java source code for a project. It compiles all Java source files located by default in the src/main/java directory and generates corresponding bytecodes (.class files) in the target/classes directory. To use the "compile" command in Maven, open a terminal or command prompt, navigate to the root directory of the Maven project (where the pom.xml file resides), and run the following command:

mvn compile

The "test" command
The "test" command in Maven is used to execute unit tests defined in a Maven project. It automatically runs all test cases written in the project and provides feedback on their success or failure. This command is used during development to ensure code correctness, and for continuous integration processes.

mvn test

The "package" command
The "package" command in Maven: This command is used to package a project into a distributable format such as JAR (Java Archive) or WAR (Web Archive). It compiles source code, runs tests and creates output artifacts.

 mvn package

The "install" command
The "install" command in Maven: This command builds the project and installs the artifacts into the local Maven repository. Local repositories are usually located in the ".m2" directory of the user's home folder. Other projects on the same computer can then refer to this installed project as a dependency.

 mvn install

The "deploy" command
The "deploy" command in Maven: This command is used to deploy project artifacts to a remote repository, such as a Maven repository manager. It is typically used to share a project with other developers or to deploy it to production.

mvn deploy

Guess you like

Origin blog.csdn.net/weixin_43485737/article/details/132339850