maven常用插件配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven常用插件配置相关的知识,希望对你有一定的参考价值。

1、maven-jar-plugin插件
<build>
<plugins>
<!-- 排除资源文件中的properties文件,不需要打到jar中,后面通过assembly插件打包到conf目录中 -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.conf</exclude>
</excludes>
<fileNameMapping>no-version</fileNameMapping>
</configuration>
</plugin>
</plugins>
</build>
这个插件通常不需要手动指定,默认mvn install 的时候就会运行,但是如果想排除某些资源文件,就需要手动指定一下了

2、maven-dependency-plugin
<plugin>
<!-- maven-dependency-plugin 会拷贝所有依赖的jar包,包括传递依赖的jar包都会拷贝 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
maven默认是不理会项目所依赖的jar包的,但是如果要发布项目,需要通过maven-dependency-plugin将项目所依赖的jar包输出到lib目录;
maven-dependency-plugin 会拷贝所有依赖的jar包,包括传递依赖的jar包都会拷贝,比如项目依赖于a.jar,而a.jar的项目依赖b.jar,c.jar,
那么maven-dependency-plugin会将a.jar,b.jar,c.jar一起拷贝到项目的lib目录


3、如果项目要发布源码,需要用到maven-source-plugin
<!-- Source attach plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>


4、maven-release-plugin
<!-- package release plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
</plugin>
这个插件暂时还不知道有什么用



5、maven-Javadoc-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

6、maven-war-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<excludes>
<exclude>**/*.jpg</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
这个插件通常不需要手动指定,默认mvn install 的时候就会运行,但是如果想排除某些资源文件,就需要手动指定一下了


pasting

以上是关于maven常用插件配置的主要内容,如果未能解决你的问题,请参考以下文章

Maven基本概念——常用插件的配置

maven常用插件pom配置

maven常用插件整理

配置 VScode 编辑器 (前端篇)

Jacoco和Tycho surefire的Eclipse RCP插件代码介绍

maven之常用插件