1.官网下载maven包,安装配置环境:
mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/maven-3.6.3
Java version: 14, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home
Default locale: zh_CN_#Hans, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
2.修改settings.xml文件
- 指定本地仓库目录
<localRepository>/data/maven/repo</localRepository>
- 配置镜像,指定下载jar包地址(如:阿里镜像源)
3.idea编辑器(eclipseIntellij idea)设置
- 指定本地maven目录
- 指定maven的settings文件路径,同时idea访问的repository仓库也对应变化
4.maven项目创建
5.maven项目结构
- src/main/java 代码目录
- src/main/resources 资源文件目录
- src/test/java 单位测试代码目录
- src/test/resources 测试资源文件目录
- Maven Dependencies 通过maven拉取的项目依赖包存放目录
- target 存放构建后文件的目录
6.maven官方仓库查看依赖包
www.mvnrepository.com
7.maven构建
mvn package clean
mvn package
附加参数:
-DskipTests # 不执行测试用例,但编译测试用例类生成相应的class文件至target/test-classes下
-Dmaven.test.skip=true # 不执行测试用例,也不编译测试用例类
其他问题:
指定maven-complier-plugin编译打包时的JDK版本
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
maven打包指定main入口插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.chq.ddns.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>