Dependency configuration
- Dependency: Refers to the jar package required for the current project to run. A project can introduce multiple dependencies
- Configuration:
- Write the <dependencies> tag in pom.xml
- Use <dependency> in the <dependencies> tag to introduce coordinates
- Define the groupId, artifactacId, version of the coordinates
- Click the refresh button to import the newly added coordinates
ps: If the imported dependency does not exist in the local warehouse, it will connect to the remote warehouse/central warehouse, and then download the dependencies; if you do not know the coordinate information of the dependencies, you can go to Maven Repository: Search/Browse/Explore (mvnrepository.com) to query
dependency transitive
- Dependency is transitive
- Direct dependency: the dependency relationship established through dependency configuration in the current project
- Indirect dependency: If the dependent resource depends on other resources, the current project indirectly depends on other resources
- There will also be FirstTest in the WebTest project: 1.0/2.0Jar package
Specific examples are as follows:
First prepare multiple interdependent maven projects
First look at the pom.xml file of the A project
Where A project depends on B project
The pom.xml file in the same B project shows
Project B depends on project C
Finally look at the C project
From the above, it can be known that project A does not directly depend on project C, but indirectly depends on project C through project B.
The specific diagram is as follows:
ps: In the professional version of the two point idea, you can view the dependencies of the maven project through the view
details as follows:
Right-click the icon in the maven project that needs to be viewed--Show dependencies
The final result is as follows:
to clearly show dependencies
- Exclude dependencies: When actively disconnecting dependent resources, the excluded resources do not need to specify a version
Exclude dependencies by using the <exclusions></exclusions> tag in the pom.xml file
Taking the above project A as an example, the operation is as follows:
looking at dependencies
Completed dependency exclusion
Dependency scope
- The dependent jar package, by default, can be used anywhere. The scope of use can be set through the <scope>...</scope> tag , the scope of action:
- The scope of the main program is valid. (within the scope of the main folder)
- The test program scope is valid. (in the scope of the test folder)
- Whether to participate in packaging and running. (package directive scope)
- Common values of scope
Maven life cycle
Mavnen's life cycle is to abstract and unify all maven project build processes
There are 3 sets of independent life cycles in Maven
- clean: cleaning work
- default: core work: compilation, testing, packaging, installation, deployment, etc.
- site: Generate reports, publish sites
-
clean life cycle: This life cycle is used to clean up the project, including deleting generated files and directories. It includes the following stages:
- pre-clean: perform pre-cleaning preparations.
- clean: Clean generated files and directories.
- post-clean: the operation after cleaning.
-
default life cycle: This life cycle is the core life cycle of building projects, used for compilation, testing, packaging, deployment, etc. It includes the following stages:
- validate: Validates that the item is correct and all necessary information is available.
- compile: Compile the source code of the project.
- test: Test the compiled source code with an appropriate unit testing framework.
- package: Package compiled code into a distributable format, such as JAR.
- verify: Check the results of integration tests.
- install: Install the package to the local warehouse for use by other local projects.
- deploy: Copy the final package to a remote repository for use by other developers and projects.
-
site life cycle: This life cycle is used to generate the project's site documentation. It includes the following stages:
- pre-site: perform preparatory work before generating site documents.
- site: Generates the project's site documentation.
- post-site: operations after generating site documents, such as deploying the site to the server.
- site-deploy: Deploy the generated site documentation to the server.
ps: In the same set of life cycle , when the later stage is run, the previous stage will be run
execution life cycle
- In the idea, on the maven toolbar on the right, select the corresponding life cycle, double-click to execute
- On the command line, execute the command
- mvn + stage name to execute
- mvn clean
- mvn + stage name to execute
ps: The operation of each life cycle is completed through the corresponding plug-in, the essence of mavne is a plug-in execution framework