博主首页

maven里面pom文件的各标签介绍

       由于maven在工作中经常使用,但是平时要记的知识点有点多,偶尔回头来看一些东西难免忘记,特此整理一篇笔记,方便大家搜索查询,也方便自己以后查询!

后续碰见其他的标签也会进行更新!

      maven的pom文件中存在引入依赖、声明、继承;引入依赖的时候首先去本地仓库找,找不到再去配置的其他仓库找!

 1.modelVersion

 <modelVersion>4.0.0</modelVersion><!--描述这个POM文件是遵从哪个版本的项目描述符。-->

   2.parent

  <parent><!--父级依赖,继承-->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

  3.dependencies

 <dependencies><!--引入依赖-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

4.dependencyManagement

 <!--声明依赖,如果dependencies中没有声明版本就会来这里面找-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.BUILD-SNAPSHOT</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

5.repositories

<!--   &lt;!&ndash;相当于配置远程仓库&ndash;&gt;
    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/libs-snapshot</url>
            &lt;!&ndash;是否自动更新&ndash;&gt;
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

6.properties

 <properties><!--定义的标签属性可以在其他地方读取-->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>eureka.EurekaApplication</start-class>
        <java.version>1.8</java.version>
        <docker.image.prefix2></docker.image.prefix2>
    </properties>

7.pluginRepositories

  &lt;!&ndash;插件仓库&ndash;&gt;
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/libs-snapshot-local</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/libs-milestone-local</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>-->

 8.配置jdk版本

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
   </build>

 打包相关

        <resources>
            <resource>
                <!-- 指定资源文件位置 -->
                <directory>src/main/resources</directory>
                <!-- 处理文件时,需要对文件进行变量替换 -->
                <filtering>true</filtering>
                <excludes>//指定需要排除的文件
                    <exclude>application-dev.properties</exclude>
                    <exclude>application-prod.properties</exclude>
                    <exclude>application-test.properties</exclude>
                    <exclude>logback-prod.xml</exclude>
                </excludes>
            </resource>
            <resource>
                <!-- 指定资源文件位置 -->
                <directory>src/main/resources</directory>
                <!-- 处理文件时,需要对文件进行变量替换 -->
                <filtering>true</filtering>
                <includes>//指定需要包含的文件
                    <include>application.properties</include>
                    <include>lib/**</include>
                    <include>application-${profiles.active}.properties</include>
                    <include>logback-${profiles.active}.xml</include>
                </includes>
            </resource>
        </resources>

plugins定义插件
  
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.6.3</version> <!-- 使用你所需的Spring Boot版本 -->
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal> <!-- 可以打包成可执行的 JAR -->
                    </goals>
            
              <configuration>
                            <layout>ZIP</layout>
                            <includes>
                                <include>
                                    <groupId>non-exists</groupId>//打包将依赖包移除在外,如果有需要一起打包的则填上对应的jar包groupId
                                    <artifactId>non-exists</artifactId>
                                </include>
                            </includes>
                      </configuration>

 

                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/lib</outputDirectory>//将所有依赖复制到这个目录
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

 


           //打包将静态资源文件排除

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <!-- <excludes> <exclude>lib/**</exclude> <exclude>**/*.properties</exclude> <exclude>**/*.xml</exclude> <exclude>**/*.yml</exclude> <exclude>**/*.txt</exclude> <exclude>static/**</exclude> <exclude>templates/**</exclude> <exclude>public/**</exclude> <exclude>public-v3/**</exclude> <exclude>public-v3-prod/**</exclude> <exclude>public-v3-test/**</exclude> </excludes>--> <includes> <include>com/**</include> </includes> </configuration> </plugin>

     移动、复制、删除等相关操作

<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.runtime.classpath" /> <property name="dist">target/${project.artifactId}</property><!--target/syh-prom-h5--> <property name="res">target/${project.artifactId}/resources</property><!--target/syh-prom-h5/resources--> <property name="app-name">${project.artifactId}-${project.version}</property> <property name="real-app-name">${project.artifactId}</property> <mkdir dir="${dist}" /><!--创建文件--> <mkdir dir="${res}" /> <move file="target/${app-name}.jar" tofile="${dist}/${real-app-name}.jar" /><!--移动文件指定目录重命名--> <move todir="${dist}/lib"><fileset dir="target/lib" /></move><!--将target/lib移动至{dist}/lib--> <copy todir="${res}"> <fileset dir="target/classes"> <include name="lib/**" /> <include name="**/*.properties" /> <include name="**/*.xml" /> <include name="**/*.yml" /> <include name="**/*.txt" /> </fileset> </copy> <tar destfile="target/${real-app-name}.tar" basedir="${dist}"/><!--压缩成tar--> <gzip destfile="target/${real-app-name}.tar.gz" src="target/${real-app-name}.tar"/><!--压缩成.gz--> <delete> <fileset dir="target" includes="*.tar"/><!--删除文件--> <fileset dir="target" includes="*.original"/> </delete> </target> </configuration> </execution> </executions> </plugin>

 




 

posted @ 2018-11-30 15:24  笑~笑  阅读(5869)  评论(0编辑  收藏  举报