zoukankan      html  css  js  c++  java
  • Maven 常用 POM 配置和命令

    1、基础配置

    <groupId>com.company</groupId>
    <artifactId>project</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>
    <modules>
        <module>demo</module>
    </modules>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    1. groupId:工程ID
    2. artifactId:工程的模块ID
    3. version:版本号
    4. packaging:打包类型,默认是jar,还有war、ear、pom等
    5. modules:子工程的模块列表,相对路径
    6. properties:公共属性

    2、依赖包配置

    <dependency>
        <groupId></groupId>
        <artifactId></artifactId>
        <version></version>
        <classifier></classifier>
        <exclusions>
            <exclusion/>
        </exclusions>
        <scope></scope>
        <systemPath></systemPath>
        <type></type>
        <optional>true</optional>
    </dependency>
    1. type:包类型,默认是jar,还有war、ear、pom等
    2. classifier:分类器,jar包版本号后面的字符串就是分类,比如jarname-1.0.1-jdk8.jar,jdk8就是分类
    3. exclusions:排除依赖,常用于解决依赖冲突
    4. scope:作用域
      • compile:默认,会参与编译,以及后期的测试和运行周期
      • provided:表示打包的时候可以不打进去
      • runtime:类似compile,但是不会编译
      • test:仅参与测试相关的工作
      • system:类似provided,不过被依赖项不会从maven仓库下载,而是从本地系统拿取,需要配合systemPath使用
    5. systemPath:为system提供路径
    6. optional:为true时,依赖不会传递

    3、依赖插件

    <build>
        <plugins>
            <plugin>
                <!-- 打包成可执行的jar -->
                <groupId></groupId>
                <artifactId></artifactId>
                <version></version>
                <goals></goals>
                <dependencies></dependencies>
                <executions></executions>
                <extensions></extensions>
                <inherited></inherited>
                <configuration></configuration>
            </plugin>
        </plugins>
    </build>
    1. goals:执行目标,每个插件都有自己的goal
    2. dependencies:插件所需要的额外依赖
    3. executions:在构建生命周期中执行一组目标的配置
    4. extensions:使用来自该项目的一系列构建扩展
    5. inherited:true表示传播给子POM
    6. configuration:插件配置

    4、继承父 POM

    <parent>     
        <groupId/>    
        <artifactId/>   
        <version/>    
        <relativePath/>    
    </parent>   
    1. relativePath:父 POM 文件的相对路径,默认路径是../pom.xml

    5、依赖包管理

    子工程只需声明坐标就会继承此配置。

    <dependencyManagement>
        <dependencies>
            <dependency/>
        </dependencies>
    </dependencyManagement>

    6、依赖插件管理

    子工程只需声明坐标就会继承次配置。

    <build>
        <pluginManagement>
            <plugins>
                <plugin/>
            </plugins>
        </pluginManagement>
    </build>

    7、常用命令

    • mvn clean:清除maven的编译结果
    • mvn compile:编译
    • mvn package:编译、打包
    • mvn install:编译、打包、部署
    • –DskipTests:编译测试用例,但不执行测试
    • -Dmaven.test.skip:不编译测试用例且不执行测试
    • –Dcheckstyle.skip:不执行静态检查
    • -U:强制更新snapshot类型jar包
    • -T 4:4线程构建
    • -T 1C:根据CPU核数每个核分配1个线程构建
    • -v:显示版本信息
    • -V:显示版本信息,不停止构建
    • -o:离线模式
    • -q:安静输出 - 仅显示错误
    • -D:定义系统属性
    • -X:生成执行调试输出
    • -e:生成执行错误消息
    • -N:不要递归到子项目中
    • -nsu:禁止SNAPSHOT更新
    • -P:要激活的以逗号分隔的配置文件列表
    • -pl:以逗号分隔的指定反应堆项目列表
    • -rf:从指定项目恢复反应堆
    • 本地上传到私服:mvn deploy:deploy-file -DgroupId=groupId -DartifactId=artifactId -Dversion=version -Dfile=本地jar包路径 -DrepositoryId=releases/snapshots -Durl=仓库地址
  • 相关阅读:
    REQUIRED与REQUIRED_NEW
    springboot启动原理
    Mysql缓存的配置和使用
    Mysql-15-mysql分布式应用
    Mysql的日志管理
    Mysql的主从复制
    Mysql的备份和恢复
    Mysql-7-mysql函数
    Mysql-6-数据类型和运算符
    Mysql-5-数据表的基本操作
  • 原文地址:https://www.cnblogs.com/bigshark/p/5137393.html
Copyright © 2011-2022 走看看