• maven项目配置框架


    任何一个maven项目都会继承一个默认的父pom配置:Super POM,详见:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
    在pom.xml中可以直接使用一些变量值,如:

    ${project.groupId}               The group id of current project
    ${project.version}          The version of current project
    ${project.build.sourceDirectory} The source directory of current project
    ${project.basedir}               The directory that the current project resides in.
    ${project.baseUri}               The directory that the current project resides in, represented as an URI. Since Maven 2.1.0
    ${maven.build.timestamp}         The timestamp that denotes the start of the build. Since Maven 2.1.0-M1
    

    详见:https://maven.apache.org/guides/introduction/introduction-to-the-pom.html之Available Variables

    一个实际完整的maven项目pom.xml文件配置框架:

    <?xml version="1.0"?>
    <project
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <modelVersion>4.0.0</modelVersion>
        
        <!-- 模块参数 -->
        <artifactId>xxx-xxx</artifactId>
        <version>x.x.x</version>
        <packaging>war</packaging>
        <name>xxx</name>
        <url>xxx</url>
        
        <!-- 父模块,可选. -->
        <parent>
            <groupId>xxx</groupId>
            <artifactId>xxx</artifactId>
            <version>x.x.x</version>
        </parent>
    
        <!-- 定义属性 -->
        <properties>
            <!-- 项目编码 -->
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <!-- 时间格式 -->
            <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
        </properties>
    
        <!-- 依赖配置 -->
        <dependencies>
            <dependency>
                <groupId>xxx</groupId>
                <artifactId>xxx</artifactId>
                <version>x.x.x</version>
            </dependency>
        </dependencies>
    
        <!-- 定义profile: 将开发配置和生产配置分离开 -->
        <profiles>
            <profile>
                <id>dev</id>
                <properties>
                    <profile.dir>dev</profile.dir>
                </properties>
                <activation>
    				<activeByDefault>dev</activeByDefault>
    			</activation>
            </profile>
            <profile>
                <id>test</id>
                <properties>
                    <profile.dir>test</profile.dir>
                </properties>
            </profile>
            <profile>
                <id>prod</id>
                <properties>
                    <profile.dir>prod</profile.dir>
                </properties>
            </profile>
        </profiles>
    
        <!-- 打包 -->
        <build>
            <finalName>xxx</finalName>
            
            <!-- 打包资源 -->
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <excludes>
                        <exclude>.svn</exclude>
                        <exclude>.java</exclude>
                    </excludes>
                </resource>
                <resource>
                    <directory>src/main/resources/profiles/${profile.dir}</directory>
                    <excludes>
                        <exclude>.svn</exclude>
                    </excludes>
                </resource>
            </resources>
            
            <!-- 配置打包插件,如: 依赖处理,资源复制,压缩打包等 -->
            <plugins>
                <!-- 生成jar包时打包资源文件配置 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <excludes>
                            <exclude>**/profiles/**</exclude>
                            <exclude>**/jdbc.properties</exclude>
                            <exclude>**/*.proto</exclude>
                        </excludes>
                    </configuration>
                </plugin>
    
                <!-- 打包源码 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.0.1</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
                <!-- 打包编译参数 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
    
                <!-- 将依赖模块的jar包文件提取出来放到指定位置 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>unpack</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>unpack</goal>
                            </goals>
                            <configuration>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>com.xxx</groupId>
                                        <artifactId>xxx-xxx</artifactId>
                                        <version>1.0.0</version>
                                        <type>jar</type>
                                        <includes>**/*.class</includes>
                                        <overWrite>false</overWrite>
                                        <outputDirectory>${project.build.directory}/classes</outputDirectory>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
                <!-- 打包可执行jar文件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <transformers>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/spring.handlers</resource>
                                    </transformer>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                        <resource>META-INF/spring.schemas</resource>
                                    </transformer>
                                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>org.chench.Main</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
                <!-- 构建时不执行单元测试 -->
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-surefire-plugin</artifactId>
    				<version>2.20.1</version>
    				<configuration>
    					<skipTests>true</skipTests>
    				</configuration>
    			</plugin>
            </plugins>
        </build>
    </project>
    
  • 相关阅读:
    【docker】关于docker中挂载的解释
    【linux】centos7安装使用rz/sz命令
    【docker】 docker容器内部安装vi命令
    【docker】centOS7上部署的mysql和spring boot服务,要求,mysql的时间、java程序服务的时间和宿主机的时间完全保持一致【修改mysql时区,临时和永久】【修改spring boot配置文件时区】【修改docker启动spring boot实例程序时区】
    【docker】docker部署spring boot项目在服务器上
    【spring boot】spring boot后台时间正确,返回给前台的时间不正确,和后台差8个小时
    html页面跳转传递参数
    SpringCloud服务如何在Eureka安全优雅的下线
    使用SpringBoot Admin监控SpringCloud微服务
    对actuator的管理端点进行ip白名单限制(springBoot添加filter)
  • 原文地址:https://www.cnblogs.com/nuccch/p/7723151.html
Copyright © 2020-2023  润新知