目录
原文链接:https://www.cnblogs.com/gongnol/p/9667010.html
Maven是通过pom.xml来执行任务的,其中的build标签描述了如何来编译及打包项目,而具体的编译和打包工作是通过build中配置的 plugin 来完成。当然plugin配置不是必须的,默认情况下,Maven 会绑定以下几个插件来完成基本操作。
1.编译配置示例补充
1.1.源工程结构
1.2.源文件代码
dev.properties
app.owner=dev-dfr
password=dev-123456
pro.properties
app.owner=pro-dfr
password=pro-123456
db.properties
password=${password}
app.properties
application.owner=${app.owner}
pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>pro</id>
<properties>
<env>pro</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<build>
<directory>${basedir}/testTarget</directory>
<filters>
<filter>${basedir}/src/main/filter/${env}.properties</filter>
</filters>
<resources>
<resource>
<targetPath>${basedir}/outPutOtherResources</targetPath>
<directory>src/main/otherResources</directory>
<includes>
<include>db.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<!-- 默认路径会编译到target/classes目录下 -->
<targetPath>${basedir}/outPutResources</targetPath>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>app.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
1.3.编译后的文件结构
1.4.编译后的代码
2.插件定义
2.1.maven中默认使用的插件
在没有显示配置插件的情况下,执行mvn clean install时,maven会调用默认的plugin来完成编译打包操作,例如执行mvn clean install时会执行
maven-clean-plugin:2.5:clean (default-clean)
maven-resources-plugin:2.6:resources (default-resources)
maven-compiler-plugin:3.1:compile (default-compile)
maven-resources-plugin:2.6:testResources (default-testResources)
maven-compiler-plugin:3.1:testCompile (default-testCompile)
maven-surefire-plugin:2.12.4:test (default-test)
maven-jar-plugin:2.4:jar (default-jar)
maven-install-plugin:2.4:install (default-install)
2.2.插件自定义
若想显示的配置插件,可以在build标签中定义
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.2.RELEASE</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<testSource>${java.version}</testSource>
<testTarget>${java.version}</testTarget>
</configuration>
</plugin>
</plugins>
</build>