• 深入淺出 Apache Maven 的 Plugins 外掛機制


    Apache Maven 之所以強大,是因為他有一個強大的 Plugin 執行框架,你任何想讓 Maven 幫你完成的工作,無論是建置(Build)、封裝(Packaging)、產生報表(Reporting)、執行測試(Tests),全部都是透過 Plugins 完成的。它除了內建的核心 Plugins 之外,還有數以百計的第三方 Plugins 可以安裝使用。今天這篇文章我就來介紹一下他的基本架構與使用方式。

    簡介 Apache Maven Plugins

    基本上 Apache Maven 的 Plugins 分成兩大類,並且可以定義在專案的 pom.xml 檔案中:

    1. 建置外掛 (Build plugins)

      用來執行在 建置 (build)過程中的所有大小事,他會定義在 POM 檔的  元素底下。

    2. 報表外掛 (Reporting plugins)

      用來執行在建立 文件網站 (site)過程中的所有大小事,他會定義在 POM 檔的  元素底下。

      由於 報表外掛 (Reporting plugins)的結果會被發佈在 文件網站 (site)上,所以必須考量 多國語系 (internationalized)與 本地化 (localized)的要求。詳見 Localization of Plugins 說明。

    Apache Maven 官方支援許多 Plugins,並且詳細列在 Available Plugins 頁面中,光是這些內建的 Plugins 就可以幫我們解決 95% 以上的建置或報表工作,真的相當厲害且富有內涵,我很難在一篇文章內介紹這麼多 Plugins,只能淺淺帶過,有興趣大家可以個別研究不同的 Plugins。

    突然覺得可以所有 Plugins 都介紹的話,那就可以參加 2022 iThome 鐵人賽 了吧!:sweat_smile:

    以下我就列出這些官方支援的 Plugins 清單,大家可以看的大概,有點印象即可:

    • 核心外掛 (Core plugins)

      Plugin 類型 摘要說明
      compiler 建置 Compiles Java sources.
      deploy 建置 Deploy the built artifact to the remote repository.
      failsafe 建置 Run the JUnit integration tests in an isolated classloader.
      install 建置 Install the built artifact into the local repository.
      resources 建置 Copy the resources to the output directory for including in the JAR.
      site 建置 Generate a site for the current project.
      surefire 建置 Run the JUnit unit tests in an isolated classloader.
      verifier 建置 Useful for integration tests - verifies the existence of certain conditions.
      clean 建置 Clean up after the build.
    • 封裝外掛 (Packaging types/tools)

      Plugin 類型 摘要說明
      jar 建置 Build a JAR ( Java ARchive ) from the current project.
      war 建置 Build a WAR ( Web Application Archive ) from the current project.
      ear 建置 Generate an EAR ( Enterprise ARchive ) from the current project.
      ejb 建置 Build an EJB (and optional client) from the current project.
      rar 建置 Build a RAR ( Resource Adapter Archive ) from the current project.
      app-client/acr 建置 Build a JavaEE application client from the current project.
      shade 建置 Build an Uber-JAR from the current project, including dependencies.
      source 建置 Build a source-JAR from the current project.
      jlink 建置 Build Java Run Time Image .
      jmod 建置 Build Java JMod files.
    • 報表外掛 (Reporting plugins)

      Plugin 類型 摘要說明
      changelog 報表 Generate a list of recent changes from your SCM.
      changes 建置+報表 Generate a report from an issue tracker or a change document.
      checkstyle 建置+報表 Generate a Checkstyle report.
      doap 建置 Generate a Description of a Project (DOAP) file from a POM.
      docck 建置 Documentation checker plugin.
  • 相关阅读:
    react-native webstorm 无法启动 Android 模拟器
    linux usb驱动移植(1)
    【MyBatis Plus】深入探索 MyBatis Plus 的条件构造器,自定义 SQL语句,Service 接口的实现
    力扣第47天--- 第647题、第516题
    [MAF的Agent管道详解-04]如何让LLM按照要求的结构输出数据?
    菜鸟打印组件系列-vue3快速接入
    OpenGL - Framebuffers
    mencpy和strcpy的区别?
    2012年认证杯SPSSPRO杯数学建模A题(第一阶段)蜘蛛网全过程文档及程序
    FFmpeg Mp4加解密
  • 原文地址:https://blog.csdn.net/ch98000/article/details/126816102