Maven項目命名規范


Guide to naming conventions on groupId, artifactId and version
groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. Look at More information about package names.
eg. org.apache.maven, org.apache.commons

A good way to determine the granularity of the groupId is to use the project structure. That is, if the current project is a multiple module project, it should append a new identifier to the parent's groupId.

eg. org.apache.maven, org.apache.maven.plugins, org.apache.maven.reporting

artifactId is the name of the jar without version. If you created it then you can choose whatever name you want with lowercase letters and no strange symbols. If it's a third party jar you have to take the name of the jar as it's distributed.
eg. maven, commons-math

version if you distribute it then you can choose any typical version with numbers and dots (1.0, 1.1, 1.0.1, ...). Don't use dates as they are usually associated with SNAPSHOT (nightly) builds. If it's a third party artifact, you have to use their version number whatever it is, and as strange as it can look.
eg. 2.0, 2.0.1, 1.3.1


以上內容是maven官網文檔中的,命名約定指南(https://maven.apache.org/guides/mini/guide-naming-conventions.html)

總的來說:
groupId:定義當前Maven項目隸屬的實際項目,例如org.sonatype.nexus,此id前半部分org.sonatype代表此項目隸屬的組織或公司,后部分代表項目的名稱,如果此項目多模塊話開發的話就子模塊可以分為org.sonatype.nexus.plugins和org.sonatype.nexus.utils等。

特別注意的是groupId不應該對應項目隸屬的組織或公司,也就是說groupId不能只有org.sonatype而沒有nexus。

例如:我建立一個項目,此項目是此后所有項目的一個總的平台,那么groupId應該是org.limingming.projectName,projectName是平台的名稱,org.limingming是代表我個人的組織,如果以我所在的浪潮集團來說的話就應該是com.inspur.loushang。

artifactId是構件ID,該元素定義實際項目中的一個Maven項目或者是子模塊,如上面官方約定中所說,構建名稱必須小寫字母,沒有其他的特殊字符,推薦使用“實際項目名稱-模塊名稱”的方式定義,例如:spirng-mvn、spring-core等。
推薦格式:使用實際項目名稱作為artifactId的前綴,緊接着為模塊名稱
舉例:nexus-indexer、spring-mvc、hibernate-c3po……這些id都是以實際項目名稱作為前綴,然后接着一個中划線,再緊跟項目的模塊名稱,默認情況下maven會在artifactId添加version作為最后生成的名稱。例如:spirng-mvn-2.0.0.jar


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM