一.POM 文件介绍与基本组成
<dependency>
<groupId>org.sonatype.nexus</groupId>
<artifactId>nexus-indexer</artifactId>
<version>2.0.0</version>
<package>jar</package>
</dependency>
元素 | 可选值 | 描述 |
groupId | 分组ID | |
artifactId | 模块id | |
version | 版本 | |
packaging | 打包类型:pom、jar、war | |
modelVersion | 对应的超级pom 版本 | |
dependencies | 项目依懒包 |
二 maven基本命令
mvn clean :清理
mvn compile:测试
mvn test: 测试
mvn package 打包
mvn install 打包并上传到本地仓库
mvn depeloy 上传到远程仓库
mvn -Dmaven.test.skip=true 跳过测试
三.常用的maven 仓库镜像
<mirrors>
<!--仓库1 阿里云镜像仓库-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<!--中央仓库1 -->
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<!-- 中央仓库2 -->
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
四.maven 的常用插件
<!-- 修改compiler 插件已设置jre 源码版本和编译版本-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- 设置setting.xml 文件中 为profile 添加属性-->
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
</properties>
<!--生成一个源码包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>attach-source</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!--测试指定范围-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/Com*.java</include>
</includes>
</configuration>
</plugin>