关于MavenartifactID的命名约定的最佳实践(有限制吗?) [英] Best practices in naming conventions on Maven artifactID (is there restriction?)

查看:678
本文介绍了关于MavenartifactID的命名约定的最佳实践(有限制吗?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队是Maven的新手,我们无法找到有关为我们的项目选择工件ID的明确指南.

My team is new to Maven and we haven't been able to find any definitive guidance on selecting artifactIDs for our projects.

我知道命名约定指南指出工件ID应该是

I know that the Guide to naming conventions says that artifactIDs should be

您要使用小写字母且没有奇怪符号的任何名称"

"whatever name you want with lowercase letters and no strange symbols"

,但是我们小组中的某些人希望对工件ID都使用反向域名样式.

but some folks in my group want to use the reverse domain name style for both groupIDs and artifactIDs.

基于上述准则以及我在中央存储库中看到的所有示例,我认为拥有反向域样式工件ID并不有意义,但我无法确定这样做实际上是无效的还是只是皱眉.我模糊地记得曾经读过一些有关各种存储库管理器的内容,这些存储库管理器无法有效地处理包含句点(.)字符的工件ID,但是我不记得在哪里读过&我现在找不到它.

Based on the above-mentioned guidelines plus all the examples that I've seen in the central repository I don't think it makes sense to have reverse domain style artifactIDs but I can't tell if doing so is actually invalid or merely frowned upon. I vaguely remember reading something about various repository managers not being able to deal effectively with artifactIDs that contain period (.) characters but I don't remember where I read that & I can't find it now.

MavenartifactID中允许使用的字符有什么规则?

What are the rules, if any, on the characters allowed in a Maven artifactID?

推荐答案

以下是有关该主题的一些帖子:

As a beggining here some posts dealing with this subject :

  • using groupId in artifactId is now deprecated
  • sonatype trustable conventions

然后堆栈溢出!

然后,我建议您不要在artifactId中使用groupId.这是多余的;).

Then, I would suggest you to NOT use groupId in you artifactId. This is redundant ;).

我引用了似乎与您的问题最相关的sonatype文档:

I quote the sonatype docs that seems to be the most relevant for your question :

groupId 将在所有项目中唯一地标识您的项目,因此我们需要实施命名架构.它必须遵循包装 名称规则,这意味着至少必须将其作为您的域名 控制,您可以根据需要创建任意多个子组.例如. org.apache.maven,org.apache.commons 确定groupId粒度的一种好方法是使用项目结构.也就是说,如果当前项目是多个 模块项目,它应该在父项的后面附加一个新的标识符 groupId. 例如. org.apache.maven,org.apache.maven.plugins,org.apache.maven.reporting

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. 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 是不带版本的jar的名称.如果创建了它,那么您可以选择任何想要的小写字母名称 而且没有奇怪的符号.如果是第三方罐子,则必须 罐子的名称,例如它的分布.专家,下位数学

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

版本 ,如果您分发它,则可以选择任何带有数字和点(1.0、1.1、1.0.1,...)的典型版本.不要使用日期 因为它们通常与SNAPSHOT(每晚)构建相关联.如果它是 第三方工件,无论使用什么方式都必须使用其版本号 是的,而且看起来很奇怪. 2.0、2.0.1、1.3.1

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

因此,在您的groupId AND 中使用反向dns是一个不错的选择.不能在artifactId中再次使用它们.

So using reverse dns in you groupId AND your package name is a good pratice. Use them again in artifactId is not.

这篇关于关于MavenartifactID的命名约定的最佳实践(有限制吗?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆