maven学习笔记
1、maven的内置属性
${basedir}表示项目根目录
${project.basedir}同${basedir}
${project.groupId}表示项目groupId
${project.artifactId}表示项目artifactId
${version}表示项目版本
${project.version}同${version}
${project.baseUri}表示项目文件地址
${maven.build.timestamp}表示项目开始构建时间
${maven.build.timestamp.format}表示时间格式,可以如下配置
<properties>
<maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
</properties>
${project.build.directory}-->target目录
${project.build.sourceEncoding}-->UTF-8
${project.build.sourceDirectory}-->src\main\java目录
${project.build.finalName}
${project.build.outputDirectory}-->target\classes
${env.JAVA_HOME}-->取环境变量的值D:\Java\jdk1.8.0_92
maven默认的pluginManagement插件(antrun、assembly、dependency、release)
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
</plugin>
</plugins>
</pluginManagement>
maven默认的plugins插件(clean、resources、jar、compiler、surefire、insatll、deploy、site、
maven-project-info-reports-plugin)
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>F:\myWorkspace\atest\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>F:\myWorkspace\atest\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>F:\myWorkspace\atest\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
2、maven的profile的配置
profile激活方式(1)、activeProfiles写的profile将总是被激活
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
(2)、默认激活方式,通过测试也总是会被激活,和官网描述的不一样
<activation>
<activeByDefault>true</activeByDefault>
</activation>
(3)、条件激活方式,激活条件有多个时要同时满足
mvn clean install -Dtarget=dev这样子才能激活
<activation>
<property>
<name>target</name>
<value>dev</value>
</property>
</activation>
mvn clean install -Dtarget这样子就能激活
<activation>
<property>
<name>target</name>
</property>
</activation>
(4)、当文件存在时激活
<activation>
<file>
<exists>target</exists>
</file>
</activation>
(5)、当文件不存在时激活
<activation>
<file>
<missing>target</missing>
</file>
</activation>
(6)、当文件存在且target参数不存在且jdk为1.8时才激活
<activation>
<file>
<exists>${swagger-properties}</exists>
</file>
<property>
<name>!disableSwaggerJsonAutoGeneration</name>
</property>
<jdk>1.8</jdk>
</act