Guide to naming conventions on groupId, artifactId, and version
groupId
uniquely identifies your project across all projects. A group ID should follow Java’s package name rules. This means it starts with a reversed domain name you control. For example,
org.apache.maven
, org.apache.commons
Maven does not enforce this rule. There are many legacy projects that do not follow this convention and instead use single word group IDs. However, it will be difficult to get a new single word group ID approved for inclusion in the Maven Central repository.
You can create as many subgroups as you want. 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
. For example,
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. For example,
2.0
, 2.0.1
, 1.3.1
Maven坐标简介
每个maven项目都有一个坐标。
groupId + artifactId + version + packaging + classifier 这五个维度的坐标可以唯一确定一个依赖包,任何一个项目都是用这五个坐标唯一定位到一个发布包。
实际生产中用的最多的是groupId + artifactId + version这三个维度,后面两个维度99%的情况下用不到。
我们需要在pom.xml里配置需要的依赖的坐标,然后maven会自动从中央仓库下载后缓存到本地仓库里。
打包的时候,可以通过插件直接将本地仓库中的依赖打入jar包中,形成一个完整可用的发布包
由于我们自己的maven项目有时候也可能要发布到maven仓库中给别的项目使用,因此maven是强制性要求每个项目都要定义一个坐标。
————————————————
版权声明:本文为CSDN博主「喵了个汪q」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_45408935/article/details/120724067