Maven工件和groupId命名 [英] Maven artifact and groupId naming
问题描述
我目前正在将一些项目从Ant移到Maven.像我一样,我想使用完善的约定来查找groupId
和artifactId
,但是我找不到任何详细的约定(有一些约定,但是它们没有涵盖我想知道的要点. ).
I'm currently in the process of moving some project from Ant to Maven. Conformist as I am, I want to use well-established conventions for finding groupId
and artifactId
, but I can't find any detailed conventions (there are some, but they don't cover the points I'm wondering about).
以这个项目为例,首先是Java包:com.mycompany.teatimer
Take this project for instance, first the Java package: com.mycompany.teatimer
Tea timer 实际上是两个词,但是Java包命名约定禁止插入下划线或连字符,因此我将它们全部编写在一起.
Tea timer is actually two words, but the Java package naming conventions forbid the insertion of underscores or hyphens, so I'm writing it all together.
我选择与软件包ID相同的groupId
,因为我认为这是个好主意.是吗?
I chose the groupId
identical to the package ID because I think that's a good idea. Is it?
最后,我必须选择一个artifactId
,我现在去了teatimer
.但是当我查看其他Maven项目时,它们使用连字符在artifactId
中拆分单词,如下所示:tea-timer
.但是当连接到groupId
:com.mycompany.teatimer.tea-timer
时,看起来确实很奇怪.
Finally, I have to pick an artifactId
, I currently went for teatimer
. But when I look at other Maven projects, they use hyphens to split words in artifactId
s, like this: tea-timer
. But it does look weird when concatenated to the groupId
: com.mycompany.teatimer.tea-timer
.
您将如何做?
另一个例子:
包裹名称:com.mycompany.awesomeinhouseframework
groupId
:com.mycompany.awesomeinhouseframework
(?)
artifactId
:awesome-inhouse-framework
(?)
推荐答案
您的约定似乎很合理.如果要在Maven存储库中搜索您的框架,我会在com.mycompany.awesomeinhouseframework
组目录中寻找awesome-inhouse-framework-x.y.jar
.我会根据您的约定在那找到它.
Your convention seems to be reasonable. If I were searching for your framework in the Maven repo, I would look for awesome-inhouse-framework-x.y.jar
in com.mycompany.awesomeinhouseframework
group directory. And I would find it there according to your convention.
两个简单的规则对我有用:
Two simple rules work for me:
- reverse-domain-packages for groupId (since such are quite unique) with all the constrains regarding Java packages names
- project name as artifactId (keeping in mind that it should be jar-name friendly i.e. not contain characters that maybe invalid for a file name or just look weird)
这篇关于Maven工件和groupId命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!