总结了maven对jar、source、resources、dependces打包的plugin,理解的不是很全面仅供参考。
<plugins>
<!-- 配置文件 -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- 输入文件路径 -->
<outputDirectory>${basedir}/project/</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<!--需要打包的内容 -->
<includes>
<include>conf/env/**</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- 排除的内容 -->
<excludes>
<exclude>conf/xml/**</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- 用于拷贝maven依赖的plugin yes -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<!-- 把依赖的所有maven jar包拷贝到lib目录中(这样所有的jar包都在lib目录中) -->
<outputDirectory>${basedir}/project/lib</outputDirectory>
<!-- jar依赖的jar是否包含,一般都是需要的所以false -->
<excludeTransitive>false</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
<!-- 源码文件 执行 mvn install,maven会自动将source install到repository 。 执行 mvn deploy,maven会自动将source
deploy到remote-repository 。 执行 mvn source:jar,单独打包源码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<!-- <phase>verify</phase> -->
<goals>
<!-- <goal>jar</goal> -->
<goal>jar-no-fork</goal><!-- 只会在phase期间 -->
</goals>
</execution>
</executions>
<configuration>
<!-- <outputDirectory>${basedir}/project/lib</outputDirectory> -->
</configuration>
</plugin>
<!-- 项目打包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<!-- 下面那个可以见jar移动到指定的目录 -->
<!-- <executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/project/lib</outputDirectory>
</configuration>
</execution>
</executions> -->
</plugin>
</plugins>