我目前正在把一些项目从Ant转移到Maven。我是一个墨守成规的人,我想使用完善的约定来查找groupId和artifactId,但我找不到任何详细的约定(有一些,但它们不包括我想知道的要点)。
以这个项目为例,首先是Java包:com.mycompany.teatimer
Tea timer实际上是两个单词,但是Java包命名约定禁止插入下划线或连字符,所以我把它们写在一起。
我选择了与包ID相同的groupId,因为我认为这是一个好主意。是吗?
最后,我必须选择一个artifactId,我目前去了teatimer。但是当我查看其他Maven项目时,它们使用连字符分隔artifactid中的单词,例如:tea-timer。但是当连接到groupId: com.mycompany.teatimer.tea timer时,它看起来确实很奇怪。
你会怎么做呢?
另一个例子:
包名:com.mycompany.awesomeinhouseframework
groupId: com.mycompany.awesomeinhouseframework ?
artifactId: awesome-in - house-framework (?)
奇怪与否是非常主观的,我只是建议遵循官方的建议:
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