内置变量
${basedir}表示项目根目录,即包含pom.xml文件的目录;${version}表示项目版本;${project.basedir}同${basedir};${project.baseUri}表示项目文件地址;${maven.build.timestamp}表示项目构件开始时间;${maven.build.timestamp.format}表示属性${maven.build.timestamp}的展示格式,默认值为yyyyMMdd-HHmm,可自定义其格式,其类型可参考java.text.SimpleDateFormat。${project.build.directory}表示主源码路径;${project.build.sourceEncoding}表示主源码的编码格式;${project.build.sourceDirectory}表示主源码路径;${project.build.finalName}表示输出文件名称;${project.version}表示项目版本,与${version}相同;${project.xxx} 当前pom文件的任意节点的内容${env.xxx} 获取系统环境变量。${settings.xxx} 指代了settings.xml中对应元素的值。
资源管理
<resources> <resource> <directory>src/main/java</directory> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> <resource> <directory>src/main/webapp</directory> <!--注意此次必须要放在此目录下才能被访问到 --> <targetPath>META-INF/resources</targetPath> <includes> <include>**/**</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/**</include> </includes> <filtering>false</filtering> </resource> </resources>
插件
- maven-compiler-plugin 编译插件
- maven-jar-plugin Jar包插件
- maven-source-plugin 资源插件
- maven-dependency-plugin 依赖插件
- maven-assembly-plugin 打包插件
- maven-surefire-plugin TestCase插件,忽略测试用例
- spring-boot-maven-plugin SpringBoot打包插件
maven-compiler-plugin
<!-- 设置maven编译的jdk版本,maven3默认用jdk1.5,maven2默认用jdk1.3 --><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <!-- 源代码使用的JDK版本 --> <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 --> <encoding>UTF-8</encoding><!-- 字符集编码 --> <skipTests>true</skipTests><!-- 跳过测试 --> </configuration> </plugin>
maven-jar-plugin
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 --><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <classesDirectory>target/classes/</classesDirectory> <archive> <manifest> <mainClass>com.alibaba.dubbo.container.Main</mainClass> <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 --> <!--自动加载META-INF/spring目录下的所有Spring配置--> <useUniqueVersions>false</useUniqueVersions> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration></plugin>
maven-source-plugin
<!-- 在多项目构建中,将source-plugin置于顶层或parent的pom中并不会发挥作用,必须置于具体项目的pom中。 --><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>
maven-resource-plugin
<!-- 该插件处理项目的资源文件拷贝到输出目录。可以分别处理main resources 和 test resources。 --><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.1</version> <configuration> <encoding>UTF-8</encoding> </configuration></plugin>
maven-dependency-plugin
<!-- 自动拷贝jar包到target目录 --><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-dependencies</id> <phase>compile</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <!-- ${project.build.directory}为Maven内置变量,缺省为target --> <outputDirectory>${project.build.directory}/lib</outputDirectory> <!-- 表示是否不包含间接依赖的包 --> <excludeTransitive>false</excludeTransitive> <!-- 表示复制的jar文件去掉版本信息 --> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin>
maven-assembly-plugin
```xml
maven-assembly-plugin
3.0.0
jar-with-dependencies
make-assembly
package
single
<a name="h57gC"></a>## maven-surefire-plugin```xml<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin>-- mvn package -DskipTests-- mvn package -Dmaven.test.skip=true-- mvn test -Dtest=RandomGeneratorTest
spring-boot-maven-plugin
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>1.4.2.RELEASE</version> <configuration> <mainClass>com.yunio.pandabank.mock.MockAppliction</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions></plugin>