current position:Home>Maven detailed installation and use

Maven detailed installation and use

2022-01-27 02:41:55 Java mage

Maven:

Maven The problem before it happened :

Suppose you are working on a project , There must be some in the project jar package , for instance mybatis,log4j,JUnit etc. , In addition to these , You may use other things developed by your colleagues , For example, others have made a financial module or a settlement module , You may need these things here . If one day your project mybatis Made an upgrade , But it's used internally JUnit No upgrade , After you upgrade mybatis If you want to use 5.0 Of JUnit, And what you are currently using in your project is 4.0 Of , Will there be conflict ? There is bound to be a problem ! It will be troublesome to manage at this time , You need various adjustments . What is more , If a colleague upgrades these things but doesn't inform you , This is the time , There will be several serious problems :

  1. jar Package inconsistency ,jar Are not compatible
  2. The engineering upgrading and maintenance process is cumbersome

Maven The essence of is a project management tool , Abstract the project development and management process into a project object model (POM)

Maven By loading pom.xml This configuration file can know the relevant information of our project , If we do 8 A project , The corresponding is 1 File , still 8 File ? Must be 8 individual !

Maven How to help us manage project resources ?

  • adopt Dependency management
  • The so-called dependency management is maven A management of all dependent resources of a project , It is a two-way relationship with the project , When we were working on the project maven Dependency management can help you manage other resources you need , When other projects need to rely on our projects ,maven We will also manage our project as a resource , This is a two-way relationship .

Maven Where do the dependent management resources exist ?

  • Local warehouse private server 、 The central warehouse
  • As the name suggests, a local warehouse is a kind of resource warehouse stored locally , If there are no relevant resources in the local warehouse , You can get it from the private server , Private server is also a resource warehouse , It's just not local , It's a remote warehouse , If there are no relevant resources on the private server , You can go to the central warehouse to get , The central warehouse is also a remote warehouse .
  • Maven In addition to helping us manage project resources, it can also help us build the project , Manage the entire life cycle of the project , Of course, these functions need to be completed by using some related plug-ins , Of course, plug-ins need to be used together throughout the life cycle , A single cannot complete the complete life cycle .

Maven The role of :

  1. The project build : Provide standard , How to build projects automatically across platforms
  2. Dependency management : Conveniently and quickly manage the resources that the project depends on (jar package ), Avoid version conflicts between resources
  3. Unified development structure : Provide standard , Unified project development structure

 Insert picture description here

Description of resource types stored in each directory :

  • src/main/java: project java Source code
  • src/main/resources: Project related configuration files ( such as mybatis To configure ,xml Mapping configuration , Custom configuration files, etc )
  • src/main/webapp:web resources ( such as html,css,js etc. )
  • src/test/java: Test code
  • src/test/resources: Test related configuration files
  • src/pom.xml: project pom file

Maven Environment building :

maven Its official website :http://maven.apache.org/
Official download address :http://maven.apache.org/download.cgi

maven Description of each directory structure :

  • bin: Executable Directory
  • boot:maven Its own boot loader
  • conf:maven Storage directory of configuration files
  • lib:maven The storage directory of the library required for running

Win/Mac System environment configuration :

Win The system configuration :
Good configuration JAVA_HOME environment variable

  1. My computer --------> attribute ---------> Advanced system setup ----------> New system variable MAVEN_HOME

The value of the system variable is maven The root directory of the software

  1. After the environment variables are configured, you need to test the environment configuration results , stay DOS Enter the following command in the command window to view the output , If you can see the output maven The version information of indicates that the configuration is successful
mvn -v

MacOs The system configuration :

  1. Download the inside apache-maven-3.6.1-bin.tar.gz Extract to the specified directory
  2. Find a convenient directory with low level and create a new folder , Create a repository The folder is used as a local warehouse , And then maven in conf Under the settings.xml Copy it over
  3. Then edit conf Under the settings.xml The configuration file ( The two configuration files should be consistent ), Add local warehouse and Alibaba image , Put it in <mirrors> in , Put it casually in the local warehouse

overall situation settings And parts settings:

  • overall situation settings: In the current computer Maven Common configuration
  • Local settings: Configuration of the current user ( The local warehouse is local )
   <!--  Configure alicloud image  -->
   <mirrors>
    	<mirror>
        	<id>nexus-aliyun</id>
        	<mirrorOf>central</mirrorOf>
        	<name>Nexus aliyun</name>
        	<url>http://maven.aliyun.com/nexus/content/groups/public</url>
   		</mirror>
    </mirrors>

    <!--  Local repository  -->
    <localRepository> Write your local warehouse Path here </localRepository>
  1. Open terminal input vim ~/.bash_profile add to maven Path information , The last two lines are
# maven To configure 
export MAVEN_HOME=/Users/itzhuzhu/java/apache-maven-3.6.3
export PATH=$PATH:$MAVEN_HOME/bin
  1. Execute after exiting source .bash_profile refresh , Then input mvn -v The following shows the successful configuration
itzhuzhu:~ itzhuzhu$ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/itzhuzhu/java/apache-maven-3.6.3
Java version: 11, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
itzhuzhu:~ itzhuzhu$ 

Warehouse :

  • Warehouse : Used to store resources , Mainly all kinds of jar package
  • The central warehouse :maven The warehouse maintained by the team itself , Everything in it jar Packages are open source
  • Private clothes : Companies / A warehouse that stores resources in a small area such as a department , Private servers can also obtain resources from the central warehouse
    • The role of private servers :
    1. Save copyrighted resources , Including purchased or self-developed jar
    2. Solve the problem of slow speed of central warehouse in remote access
    3. Share resources within a certain range , It can only be opened to the inside and not to the outside world
    4. Local access to private servers , If you have a private server, you can directly return to , If not, go to the central warehouse to get
  • Local repository : A repository where developers store resources on their own computers , Resources can also be obtained from remote warehouses

 Insert picture description here

coordinate :

coordinate :maven The coordinates in describe the location of resources in the warehouse
https://repo1.maven.org/maven2/
maven The role of coordinates :

Use a unique logo , Uniqueness defines the resource location , Through this identification, the identification and download of resources can be completed by the machine .

maven The main components of the coordinates are as follows :

  • groupId: Defines the name of the organization to which the current resource belongs ( Usually domain name reverse writing , Such as :org.mybatis;com.itheima)

  • artifactId: Defines the name of the current resource ( Usually the project or module name , Such as :crm,sms)

  • version: Defines the version number of the current resource

  • packaging: Define how resources are packaged , There are generally three values as follows

    1. jar: The resource is marked as jar package , The default is jar
    2. war: The resource is marked as war package
    3. pom: This resource is a parent resource ( Indicate the use of maven Sub module management ), When packaging, only one pom.xml No generation jar Or other package structures

If you want to query maven The coordinates of a resource , You can go to maven Query the warehouse of ,https://mvnrepository.com/, In this website, you can directly search the resources you want , Then you can get the coordinates of the resource

maven Build command :

maven The build command for is in the form of mvn start , Add function parameters later , You can execute multiple commands at once , Separate... With spaces , These in idea No manual operation required .

mvn compile: compile

  • After the compilation is completed, it will be in the project project-java There is an additional directory under target, In this directory is stored maven Some compiled things and bytecode files

mvn clean: clear

  • You need to delete these files to execute mvn clean Command is enough , After cleaning target The directory disappeared

mvn test: test

  • Which produces test-classes Is the bytecode file of the test code ,surefire-reports It's the test report it produces

mvn package: pack

  • Execute the test program in the test package , Just execute mvn test Command is enough

mvn install: Install to local warehouse

  • The output will find mvn install When the command is executed, the previous commands will also be executed
  • maven Is in accordance with the groupId/artifactId/version The structure is stored in a local warehouse

idea To configure maven:

  1. newly build java Project selection maven
     Insert picture description here

  2. newly build web Choose this project
     Insert picture description here

  3. open idea Set up search maven, Then modify the following three addresses
     Insert picture description here

  4. After you create it, check maven Project format and dependency
     Insert picture description here

pom analysis :

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <!-- Appoint pom The version of the model -->
    <modelVersion>4.0.0</modelVersion>
    <!-- packaging ,web hit wer package ,java hit jar package -->
    <packaging>war</packaging>

    <name>untitled2</name>
    <!-- Organization name -->
    <groupId>org.example</groupId>
    <!-- Project name -->
    <artifactId>untitled2</artifactId>
    <!-- edition -->
    <version>1.0-SNAPSHOT</version>

    <!-- Set all dependencies of the current project -->
    <dependencies>
        <!-- Specific dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <!-- structure -->
    <build>
        <!-- Set up the plugin -->
        <plugins>
            <!-- Specific plug-ins -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat-maven-plugin-it</artifactId>
                <version>2.1</version>
            </plugin>
        </plugins>
    </build>

</project>

Check maven Can I download :

After countless hours of error reporting, I have summarized the reasons for the error reporting, most of which are the following points :

  1. The label is in the wrong position
  2. Using a remote warehouse , It can't be downloaded , The solution is settings.xml Add Ali image , Put it on In the label
  3. Configure local warehouse , On both sides settings.xml The documents should be consistent
  4. idea Configure global maven route
  5. Find... On your computer .m2 Folder , Just kill it all
  6. Look again .lastUpdate This kind of document , Kill it all

Put the following commonly used jar Import test download speed :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.itzhuzhu</groupId>
    <artifactId>test</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.12</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.0.3</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.12.0-rc1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.12.0-rc1</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.12.0-rc1</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.8.0</version>
        </dependency>

        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>2.2</version>
        </dependency>


        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.4</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
        <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp</artifactId>
            <version>0.8.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache-core</artifactId>
            <version>2.6.8</version>
        </dependency>
        <dependency>
            <groupId>org.quartz-scheduler</groupId>
            <artifactId>quartz</artifactId>
            <version>2.2.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.29</version>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.175</version>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.2</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-xml-provider</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.1.39</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>2.2.2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>jcl-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-template</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>
        <!-- spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>4.0.2.RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.2.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-instrument</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-instrument-tomcat</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc-portlet</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-websocket</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>aopalliance</groupId>
            <artifactId>aopalliance</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.7.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>3.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.webflow</groupId>
            <artifactId>spring-webflow</artifactId>
            <version>2.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.el</artifactId>
            <version>2.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.5</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-asm</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-tx</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jdbc</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aop</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-core</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.6</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jul-to-slf4j</artifactId>
            <version>1.7.6</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.logback-extensions</groupId>
            <artifactId>logback-ext-spring</artifactId>
            <version>0.1.1</version>
        </dependency>
    </dependencies>

</project>

Maven Dependency management :

Dependency refers to the required to run in the current project jar, The format of dependency configuration is shown in the following figure

Depend on the transfer :

Depend on the transfer :

  1. Directly dependent on : Dependencies established through dependency configuration in the current project
  2. Indirect dependencies : If the dependent resource depends on other resources , It indicates that the current project is indirectly dependent on other resources
  3. Direct dependence and indirect dependence are also a relative relationship

project A Want to use the project B Things that are , Just put the project B The coordinates of are added to pom In the document , If the project B It also uses the project C Things that are , In the project A It can also be used

    <dependencies>
        <!-- project 2 Coordinates of -->
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>maven01</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

Conflict problem of dependency delivery :

Conflicts arise in the process of dependency delivery , We have three priority laws

  1. Path first : When the same resource appears in the dependency , The deeper the hierarchy , The lower the priority , On the contrary, the higher
  2. Declaration of priority : When resources are dependent at the same level , The top of the configuration sequence overrides the bottom
  3. Special priority : When different versions of the same resource are configured at the same level , The latter configuration overrides the first configuration

Optional dependency

Add optional label , Set to true,

effect : Don't want others to know what they use maven Use whatever you use... Optional

    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>maven01</artifactId>
            <version>1.0-SNAPSHOT</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

Exclude dependence :

Add exclusions, Copy the resource information to exclude
effect : Excluding dependencies means actively disconnecting dependent resources , Excluded resources do not need to execute versions , I don't want to use , Just add this

    <dependencies>
        <dependency>
            <!-- project 2 The file of -->
            <groupId>org.example</groupId>
            <artifactId>maven01</artifactId>
            <version>1.0-SNAPSHOT</version>
            <optional>true</optional>
            
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

Depend on the range :

Rely on the jar Available anywhere by default , Can pass scope The label sets its scope

The scope here mainly refers to the following three ranges

  1. The main program range is valid (src/main Within the scope of the catalog )
  2. Valid within the scope of the test procedure (src/test Within the scope of the catalog )
  3. Whether to participate in packaging (package Within the scope of the instruction )

Besides :scope There are four tag values :compile,test,provided,runtime

The correspondence between these four values and the range is as follows :

 Insert picture description here

Transitivity of dependency scope :

 Insert picture description here

Maven Life cycle :

maven The build lifecycle describes how many events a build process goes through

Life cycle is the stage of operation , The plug-in is to support the existence of the declaration cycle , The construction process depends on these two

  1. clean: Cleaning work

pre-clean: Perform some in clean Previous work

clean: Remove all files from the last build

post-clean: Perform some in clean Immediately after that

  1. default: The core work , For example, compile , test , pack , Deployment, etc.

perform test Then put test All the previous ones are executed once , perform default Just put default All the previous ones are executed again , And so on

 Insert picture description here

  1. site: Generate reports , Publishing sites, etc

pre-site: Do some work before generating site documents
site: Generate site documentation for the project
post-site: Perform some work done after generating the site document , Prepare for deployment
site-deploy: Deploy the generated site document to a specific server

plug-in unit :

  • A plug-in is bound to a phase in its lifecycle , Execute the corresponding plug-in when the corresponding life cycle is executed
  • maven By default, preset plug-ins are bound in each life cycle to complete the corresponding functions
  • The plug-in can also complete some custom functions

The configuration of the plug-in is as follows :

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <goals>
                        <!--  You can pack multiple bags  -->
                            <goal>jar</goal>
                            <goal>test-jar</goal>
                        </goals>
                        <phase>generate-test-resources</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>

stay maven There is an introduction to plug-ins on the official website :

http://maven.apache.org/plugins/index.html

copyright notice
author[Java mage],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270241503785.html

Random recommended