首页 > 其他分享 >Maven的常用插件

Maven的常用插件

时间:2024-09-01 19:14:16浏览次数:8  
标签:... 插件 plugin 常用 Maven plugins apache org maven

Apache Maven

Clean

  • Apache Maven Clean Plugin
    清理编译期在如下目录内生成的文件。

    • project.build.directory
    • project.build.outputDirectory
    • project.build.testOutputDirectory
    • project.reporting.outputDirectory
  • Plugin Documentation

  • Usage
    在命令行中执行如下命令:

    mvn clean:clean
    

    或者

    mvn clean
    

    修改pom.xml,增加如下配置:

    <project>
    ...
    <build>
      <!-- To define the plugin version in your parent POM -->
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.4.0</version>
          </plugin>
          ...
        </plugins>
      </pluginManagement>
      <!-- To use the plugin goals in your POM or parent POM -->
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-clean-plugin</artifactId>
          <executions>
            <execution>
              <id>auto-clean</id>
              <phase>initialize</phase>
              <goals>
                <goal>clean</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
        ...
      </plugins>
    </build>
    ...
    </project>
    
  • Dependency Information

  • 代码仓库

Compiler

  • Apache Maven Compiler Plugin
    对于Java项目来说,源码的默认路径为src/main/java,测试代码的默认路径为src/test/java

  • Plugin Documentation

  • Usage
    在命令行中执行如下命令:

    mvn compile
    

    或者

    mvn test-compile
    

    修改pom.xml,增加如下配置:

    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.13.0</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    
  • Compiling Sources Using A Different JDK

  • Setting the -source and -target of the Java Compiler
    修改pom.xml,增加如下配置:

    <project>
      [...]
      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
      </properties>
      [...]
    </project>
    
  • Setting the --release of the Java Compiler
    使用Java 9及以后的版本编译、构建时,可以指定编译的版本号。
    修改pom.xml,增加如下配置:

    <project>
      [...]
      <properties>
        <maven.compiler.release>8</maven.compiler.release>
      </properties>
      [...]
    </project>
    
  • Compile Using Memory Allocation Enhancements
    修改pom.xml,增加如下配置,即使用单独的javac进程,初始内存指定为128MiB,最大内存指定为512MiB

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <fork>true</fork>
              <meminitial>128m</meminitial>
              <maxmem>512m</maxmem>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>
    
  • Pass Compiler Arguments
    修改pom.xml,增加如下配置:

    <project>
      [...]
      <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <compilerArgs>
                <arg>-verbose</arg>
                <arg>-Xlint:all,-options,-path</arg>
              </compilerArgs>
            </configuration>
          </plugin>
        </plugins>
        [...]
      </build>
      [...]
    </project>
    

    相关参数,可以参考javac

JAR

  • Apache Maven JAR Plugin
    构建jar文件。
  • Plugin Documentation
  • Usage
    修改pom.xml,增加如下配置:
    <project>
      ...
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>net.jackieathome.studio</groupId>
      <artifactId>core</artifactId>
      <version>1.0-SNAPSHOT</version>
      <!-- <packaging>jar</packaging>  -->
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <version>3.4.2</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

WAR

  • Apache Maven WAR Plugin
    构建war文件。
  • Plugin Documentation
  • Usage
    修改pom.xml,增加如下配置:
    <project>
      ...
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>net.jackieathome.studio</groupId>
      <artifactId>core</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>war</packaging>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-war-plugin</artifactId>
              <version>3.4.0</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

Shade

  • Apache Maven Shade Plugin
    构建uber jar文件。
  • Plugin Documentation
  • Usage
    修改pom.xml,增加如下配置:
    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>3.6.0</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
              <execution>
                <phase>package</phase>
                <goals>
                  <goal>shade</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

Assembly

  • Apache Maven Assembly Plugin
  • Plugin Documentation
  • Usage
    修改pom.xml,增加如下配置:
    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-assembly-plugin</artifactId>
              <version>3.7.1</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
              <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
              </descriptorRefs>
            </configuration>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

Deploy

  • Apache Maven Deploy Plugin

  • Plugin Documentation

  • Usage
    修改pom.xml,增加如下配置:

    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-deploy-plugin</artifactId>
              <version>3.1.3</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-deploy-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    
  • Frequently Asked Questions

  • 代码仓库

Install

  • Apache Maven Install Plugin

  • Plugin Documentation

  • Usage
    修改pom.xml,增加如下配置:

    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-install-plugin</artifactId>
              <version>3.1.3</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

Resources

  • Apache Maven Resources Plugin
    源码资源的默认路径为src/main/resources,测试代码的资源的默认路径为src/test/resources

  • Plugin Documentation

  • Usage
    修改pom.xml,增加如下配置:

    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-resources-plugin</artifactId>
              <version>3.3.1</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    
  • Specifying a character encoding scheme

    修改pom.xml,增加如下配置:

    <project ...>
      ...
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        ...
      </properties>
      ..
    </project>
    
  • Filtering

  • Filtering Properties Files

  • Including and excluding files and directories

  • Binary filtering

Surefire

  • Maven Surefire Plugin
    执行单元测试代码。
  • Plugin Documentation
  • Usage
    修改pom.xml,增加如下配置:
    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>3.5.0</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

Failsafe

  • Maven Failsafe Plugin
    运行集成测试用例的插件。
  • Plugin Documentation
  • Usage
    修改pom.xml,增加如下配置:
    <project>
      ...
      <build>
        <!-- To define the plugin version in your parent POM -->
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-failsafe-plugin</artifactId>
              <version>3.5.0</version>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <!-- To use the plugin goals in your POM or parent POM -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>integration-test</goal>
                  <goal>verify</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          ...
        </plugins>
      </build>
      ...
    </project>
    

标签:...,插件,plugin,常用,Maven,plugins,apache,org,maven
From: https://www.cnblogs.com/jackieathome/p/18391606

相关文章

  • 【ERROR_INVALID_PIP】ESP开发环境 esp-idf v5.3 + VSCode + 插件 espressif idf 的搭
    目录一、概述二、详细安装流程1、下载安装ESP-IDF工具安装器2、配置相应的环境变量3、运行Helloworld 三、报错以及处理方法处理方法:四、结语一、概述        文章主要内容是对ESP-IDF的配置安装流程的回顾以及完成helloworld示例项目的构建与烧录,并针......
  • C++头文件<algorithm>中常用函数简介
     概述头文件algorithm(算法库)中主要提供了一些对容器操作的函数,如排序、搜索、复制、比较等,因此使用频率还是很高的,由于主要是操作容器,所以函数的语法也很类似:algorithm_name(container.begin(),container.end(),...);其中,container.begin()和container.end()分......
  • 【保姆级VSCode 插件开发之环境搭建】
    保姆级VSCode插件开发第一章VSCode插件开发入门之环境搭建文章目录保姆级VSCode插件开发前言一、准备开发环境总结前言本篇文章主要介绍VSCode插件开发环境的搭建,并创建你的第一个插件项目"HelloWorld"来熟悉具体的流程,并说明常见的问题和解决方法。一、准......
  • 【保姆级VSCode 插件开发之第一个插件项目常见问题】
    保姆级VSCode插件开发第一章VSCode插件开发入门之第一个插件项目常见问题文章目录保姆级VSCode插件开发前言一、HelloWorld插件项目常见问题和解决方案1.常见问题2.解决方法2.1针对当我们输入Ctrl+Shift+P找不到HelloWorld命令的问题2.2找到HelloWorld......
  • 一键下载微博美图,‌这款浏览器插件让你轻松拥有!‌
    300.一键下载微博图片和视频偶尔在逛微博的时候,会遇到一些不错的照片,会想要保存下。但逐个保存太麻烦了,因此在Chrome插件商店搜了下,还真有一个能一键下载的插件,来分享一波。插件地址:https://chrome.google.com/webstore/detail/bkgglniclcgkendelemfbgganhojjknh​‍‍安......
  • c++ STL常用容器使用(vector、deque、stack、queue、list、set、map等)
    1、vector使用动态数组,也叫可变数组,容器的空间是动态增长的,当空间不足时,申请更大一块空间,让后将原数据拷贝到新空间中,并释放原空间在这里插入图片描述1.1、初始化操作intarr[]={1,3,2,5};//1、方式一(初始化)vector<int>v1;//容器尾部插入数据v1.push_back(1);v1......
  • 博客园-awescnb插件-geek皮肤优化-目录优化
    ......
  • 博客园-awescnb插件-geek皮肤优化-目录优化
    ......
  • 【数模资料包】最新数模国赛word+latex模版|数模常用的算法python+matlab代码
     【2024最全国赛研赛数模资料包】C君珍贵国一数模资料|最新数模国赛word+latex模版|数模常用的算法python+matlab代码国赛指:高教社杯全国大学生数学建模竞赛,研赛指:华为杯研究生数学建模竞赛。资料内容具体看文末卡片以下是三个相关的资料内容:1C君珍贵国一数模资料2最......
  • windows系统安装配置Apache Maven
    Date:2024.07.1709:45:10author:lijianzhan电脑环境:win10系统Java开发环境:JDK21Mvn:apache-maven-3.9.9maven下载地址:https://maven.apache.org/download.cgi点击链接进入ApacheMaven官网,选择apache-maven-3.9.9-bin.zip进行下载。下载maven安装包apac......