坐标
查询网站: https://mvnrepository.com/
groupId 项目组 ID
artifactId 项目 ID
version 版本
packaging 项目的打包方式,默认值为 jar
命令
clean: 用于清理项目
validate: 验证项目是否正确以及所有必要信息是否可用
compile: 编译源代码,并移动到输出目录
test: 使用适当的单元测试框架(例如 JUnit)运行测试
package: 获取编译后的代码,并按照可发布的格式进行打包,例如 JAR、WAR 或者 EAR 文件
verify: 对集成测试的结果进行检查,以保证质量达标
install: 安装打包的项目到本地仓库,以供其他项目使用
deploy: 拷贝最终的包文件到远程仓库中,以共享给其他开发人员和项目
先执行clean后执行package
mvn clean package
IDEA配置命令
1. 选择clean和package 修改运行配置
2.直接执行
仓库
当通过 Maven 构建项目时,Maven 按照如下顺序查找依赖的构件。
- 从本地仓库查找构件,如果没有找到,跳到第 2 步,否则继续执行其他处理。
- 从中央仓库查找构件,如果没有找到,并且已经设置其他远程仓库,然后移动到第 4 步;如果找到,那么将构件下载到本地仓库中使用。
- 如果没有设置其他远程仓库,Maven 则会停止处理并抛出错误。
- 在远程仓库查找构件,如果找到,则会下载到本地仓库并使用,否则 Maven 停止处理并抛出错误。
命令方式新建
1.
mvn archetype:generate -DgroupId=com.demo -DartifactId=helloMaven -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
-DgroupId: 项目组 ID,通常为组织名或公司网址的反写。
-DartifactId: 项目名。
-DarchetypeArtifactId: 指定 ArchetypeId,maven-archetype-quickstart 用于快速创建一个简单的 Maven 项目。
-DinteractiveMode: 是否使用交互模式。
2.
mvn archetype:generate
交互的方式
POM配置
引入spring boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
固定版本
<properties>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.16.0</version>
</dependency>
</dependencyManagement>
引入依赖
<dependencies>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>2.8.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>jaxb-api</artifactId>
<groupId>javax.xml.bind</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
scope 通过配置确定依赖的范围
依赖范围 | 编译 | 测试 | 运行 | 例子 |
---|---|---|---|---|
compile(缺省) | √ | √ | √ | log4j |
test | - | √ | - | junit |
provided | √ | √ | - | servlet-api |
runtime | - | √ | √ | JDBC-driver |
system | √ | √ | - | 非 Maven 仓库的本地依赖 |
exclusions 排除依赖(一般用于依赖冲突)
聚合
<modules>
<module>jmanager-admin</module>
<module>jmanager-framework</module>
<module>jmanager-system</module>
<module>jmanager-quartz</module>
<module>jmanager-generator</module>
<module>jmanager-common</module>
</modules>
<packaging>pom</packaging>
插件和资源配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin><!--编译跳过测试文件检查的生命周期-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>com/**/dao/**Mapper.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
</build>
插件下载和依赖下载
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>