maven常用插件简介及配置模板

maven-source-plugin

简介

maven-source-plugin是maven的官方插件,在使用时可以不用指定groupId。该插件主要用于将项目的源码同jar包一起打包安装,方便使用者查看代码的逻辑和注释

使用模板

XML 复制代码
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-source-plugin</artifactId>
     <version>3.2.1</version>
     <executions>
          <execution>
               <configuration>
               <!--源码包随着项目打成的jar包安装到本地仓库或者私服、公服-->
                <attach>true</attach>
               </configuration>
                    <phase>compile</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
            </execution>
       </executions>
</plugin>

maven-assembly-plugin

简介

maven-assembly-plugin是maven的官方插件,在使用时可以不用指定groupId。该插件主要用于将项目打包成归档文件(fat-jar)

使用模板

XML 复制代码
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <!--给jar包起的别名-->
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!--默认打包之后的名称是xxxx-jar-with-dependencies.jar后缀,false表示去掉后缀-->
                    <appendAssemblyId>false</appendAssemblyId>
                    <!--该属性表示最终打成的包的名称-->
                    <finalName>test-depence-lyc</finalName>
                    <archive>
                        <manifestEntries>
                            <Premain-Class>com.xxx.performance.depence.Bootstrap</Premain-Class>
                            <Can-Redefine-Classes>true</Can-Redefine-Classes>
                            <Can-Retransform-Classes>true</Can-Retransform-Classes>
                        </manifestEntries>
                        <manifest>
                            <mainClass>com.xxx.performance.depence.TestEntry</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

maven-shade-plugin

简介

maven-shade-plugin是maven的官方插件,在使用时可以不用指定groupId。该插件可以制作归档文件(fat-jar)、包的重命名、配置文件追加等等,功能十分强大

使用模板

XML 复制代码
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <!--包重命名配置表示匹配到的包和重命名的包-->
                                    <pattern>com.alibaba</pattern>
                                    <shadedPattern>sharde.com.alibaba</shadedPattern>
                                </relocation>
                            </relocations>

                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Premain-Class>com.xxx.performance.depence.Bootstrap</Premain-Class>
                                        <Agent-Class>com.xxx.performance.depence.Bootstrap</Agent-Class>
                                        <Can-Redefine-Classes>true</Can-Redefine-Classes>
                                        <Can-Retransform-Classes>true</Can-Retransform-Classes>
                                        <mainClass>com.xxx.performance.depence.TestEntry</mainClass>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

maven-antrun-plugin

简介

maven-antrun-plugin是maven的官方插件,在使用时可以不用指定groupId。该插件用于创建指定目录,并把指定目录的文件拷贝到目标目录下

使用模板

XML 复制代码
<!--创建指定目录并拷贝jar包到指定目录-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <!--在clean阶段删除dist目录-->
                    <execution>
                        <id>clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <delete dir = "${project.basedir}\dist"/>
                            </target>
                        </configuration>
                    </execution>
                    <!--在pack阶段创建dist目录-->
                    <execution>
                        <id>package</id>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <target>
                                <mkdir dir = "${project.basedir}\dist\"/>
                                <!--注意此处的参数:file填写源文件绝对路径 tofile是目标绝对路径+需要cp之后的文件名称-->
                                <copy file = "${project.build.directory}\test-depence-1.0-SNAPSHOT-jar-with-dependencies.jar" tofile = "${project.basedir}\dist\test-depence-1.0-SNAPSHOT-jar-with-dependencies.jar" overwrite = "true"/>
                                <mkdir dir = "${project.basedir}\dist\plugins"/>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
相关推荐
蜗牛^^O^39 分钟前
Docker和K8S
java·docker·kubernetes
从心归零1 小时前
sshj使用代理连接服务器
java·服务器·sshj
IT毕设梦工厂2 小时前
计算机毕业设计选题推荐-在线拍卖系统-Java/Python项目实战
java·spring boot·python·django·毕业设计·源码·课程设计
Ylucius3 小时前
动态语言? 静态语言? ------区别何在?java,js,c,c++,python分给是静态or动态语言?
java·c语言·javascript·c++·python·学习
七夜zippoe3 小时前
分布式系统实战经验
java·分布式
是梦终空3 小时前
JAVA毕业设计176—基于Java+Springboot+vue3的交通旅游订票管理系统(源代码+数据库)
java·spring boot·vue·毕业设计·课程设计·源代码·交通订票
落落落sss3 小时前
sharding-jdbc分库分表
android·java·开发语言·数据库·servlet·oracle
码爸4 小时前
flink doris批量sink
java·前端·flink
Monodye4 小时前
【Java】网络编程:TCP_IP协议详解(IP协议数据报文及如何解决IPv4不够的状况)
java·网络·数据结构·算法·系统架构
一丝晨光4 小时前
逻辑运算符
java·c++·python·kotlin·c#·c·逻辑运算符