Maven foundation: common skills summary (1)

This article summarize Maven in common use in the basics skills.

1: GAV: Maven coordinates

  • Format Examples
    <groupId>Maven坐标之:G</groupId>
    <artifactId>Maven坐标之:A</artifactId>
    <packaging>打包方式</packaging>
    <version>Maven坐标之:V</version>

Role: locating Maven project.

2: parent of use

  • Format Examples
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/>
    </parent>

Effect: the need for a common dependency on the used portion of the plurality of management items defined in the dependent pom common parent project file, by the sub <parent> </parent>introduction

2: properties of use

  • Format Examples
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

Action: Maven can set or modify attributes properties, attributes referenced by $ {name} manner when in use.

4: Use the modules

  • Format Examples
    <modules>
        <module>子模块A</module>
        <module>子模块B</module>
        <module>子模块C</module>
        <module>子模块D</module>
        <module>子模块E</module>
    </modules>

Role: can be managed by multi-module Maven modules, the individual sub-modules with their own specific pom file, the introduction of sub-modules in the parent module by module, through the sub-module <parent> </parent>associated with the establishment of the parent module.

5: Use of dependencies

  • Format Examples
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

Action: dependencies for loading respective dependent

6: build / plugin to use

  • Format Examples
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

Action: build / plugin plug for introducing various functions, such as the example described above is to increase the compiled plug-in maven in Spring Boot (spring-boot-maven-plugin), if pom inherited spring-boot-starter-parent, then , it may not necessarily be expressly incorporated using the above configuration, since the spring-boot-starter-parent already included.

Use build / resource of: 7

  • Format Examples
    <build>
        <resources>
             <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.txt</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

Role: If there are no special settings, will follow the standard find and deal with all types of files Maven build. For example, the source directory under mybatis xml file will not be packaged, and can be set as desired by setting the resource.

8: exclusions of use

  • Format Examples
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

Role: Maven dependencies will be automatically associated with all of the jar, but inevitably inconsistent version happens, exclusion can exclude specified jar file.

9: maven-assembly-plugin using

  • Examples of Use
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <finalName>filename-demo</finalName>
                    <descriptors>
                        <descriptor>assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Used to assembly.xml example is shown below:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"  
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">  
    <id>distribution</id>  
    <formats>  
        <format>tar</format>  
    </formats>  
  
    <fileSets>
        <fileSet>  
            <directory>target</directory>  
            <outputDirectory>lib</outputDirectory>  
            <includes>  
                <include>*.jar</include>  
            </includes>  
            <excludes>  
                <exclude>*keyword.jar</exclude>  
            </excludes>  
        </fileSet>  
    </fileSets>  
</assembly>

Role: to create a final result in the form of tar files in the specified file and file information to exclude.

Released 1082 original articles · won praise 1294 · Views 4.02 million +

Guess you like

Origin blog.csdn.net/liumiaocn/article/details/104352426