Maven Available Plugins
背景
在使用maven做spring-boot web应用的时候,默认会将resources目录下的资源都打包到jar包中。但是我的应用里resources目录下有些前端库,不想打包到jar包中,不然jar包会一百多兆,去掉这些前端库就只有十几兆了。这方面的优化对部署运维人员来说省时省力不少,做docker镜像也会轻松很多。于是查找了一下maven的插件,看官方文档就很详细,不明白的地方再搜索就好。
1. Build plugins
Build plugins will be executed during the build and they should be configured in the element from the POM.
1.1 Resources Plugin
The Resources Plugin handles the copying of project resources to the output directory.
Including and excluding files and directories.
参考:http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
补充几点:
directory标签默认将所有该目录下的资源加入
如果同时使用了includes标签就只会加入includes标签里的内容
对于比较复杂的资源加入可以参考:
maven的resources介绍
可以通过使用多个resource标签来实现,比如:
下面的代码本来想只用一个resource来实现只包含父目录下指定子目录的内容,但是一个resource不能实现,使用两个resource即可:
src/main/resources/
true
assets/js/node_modules/**
assets/js/bower_components/**
assets/gentelella/vendors/**
static/gentelella/**
src/main/resources/
true
assets/js/bower_components/bootstrap/dist/
assets/js/bower_components/jquery/dist/
2. Surefire
The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats:
surefire插件是在测试阶段起作用的。可以添加对应的测试框架依赖,来进行测试,生成测试报告。
使用如下:
org.apache.maven.plugins
maven-surefire-plugin
2.18.1
org.apache.maven.surefire
surefire-junit4
2.18.1
${base.dir}/cloud.jar
${base.dir}/framwork.jar
3. 编译插件
org.apache.maven.plugins
maven-compiler-plugin
1.7
1.7
UTF-8
${base.lib.dir}
4. jar打包插件
org.apache.maven.plugins
maven-jar-plugin
package
jar
${base.lib.dir}