Maven構建 —— groupId、artifactId、version概念

前言

博主在學習Spring Maven構建的時候,經常會引入以下結構代碼:

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-indexer</artifactId>
        <version>5.2.6.RELEASE</version>
        <optional>true</optional>
    </dependency>
</dependencies>

最後它們整合成一個標識唯一資源的地址:

org.springframework:spring-context-indexer-5.2.6.RELEASE

那麼這裏的 groupId、artifactId 、version是什麼意思呢?

Maven構建

groupId

官方定義: the unique identifier of the organization or group that created the project

簡單理解:

  • 是項目組織唯一的標識符,實際對應JAVA的包的結構,是main目錄裏java的目錄結構。
  • 定義了項目屬於哪個組。

舉個例子:如果有個公司叫做單片機菜鳥,正在做一個叫做spring的項目,那麼 groupId 我們可以定義爲:

com.dpjcn.spring

artifactId

官方定義:unique base name of the primary artifact being generated by this project

簡單理解:

  • 是項目的唯一的標識符
  • 定義了當前maven項目在組中唯一的ID

舉個例子:接着上面的例子,spring項目下又分爲多個module。

spring-mvc
spring-boot
spring-ioc

version

  • 指定了myapp項目的當前版本,SNAPSHOT意爲快照,說明該項目還處於開發中,是不穩定的版本。

所以,一個完整的maven項目整體路徑:
groupId:artifactId - version

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章