Maven groupId 和artifactId 命名

发布于 2024-09-24 03:18:45 字数 809 浏览 2 评论 0原文

我目前正在将一些项目从 Ant 迁移到 Maven。由于我是墨守成规的人,我想使用既定的约定来查找 groupIdartifactId,但我找不到任何详细的约定(有一些,但它们没有没有涵盖我想知道的要点)。

以这个项目为例,首先是Java包:com.mycompany.teatimer

Tea timer实际上是两个单词,但是Java包命名约定禁止插入下划线或连字符,所以我把它们写在一起。

我选择与包 ID 相同的 groupId 因为我认为这是一个好主意。是吗?

最后,我必须选择一个 artifactId,我目前选择了 teatimer。但是当我查看其他 Maven 项目时,他们使用连字符来分割 artifactId 中的单词,如下所示:tea-timer。但当连接到groupId时,它看起来确实很奇怪:com.mycompany.teatimer.tea-timer

你会怎么做?

另一个例子:

包名称:com.mycompany.awesomeinhouseframework

groupIdcom.mycompany.awesomeinhouseframework (?)

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).

Take this project for instance, first the Java package: com.mycompany.teatimer

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.

I chose the groupId identical to the package ID because I think that's a good idea. Is it?

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 artifactIds, like this: tea-timer. But it does look weird when concatenated to the groupId: com.mycompany.teatimer.tea-timer.

How would you do this?

Another example:

Package name: com.mycompany.awesomeinhouseframework

groupId: com.mycompany.awesomeinhouseframework (?)

artifactId: awesome-inhouse-framework (?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

扬花落满肩 2024-10-01 03:18:45

奇怪是非常主观的,我只是建议遵循官方建议:

groupId、artifactId 和 version 命名约定指南

  • groupId 将在所有项目中唯一标识您的项目,
    所以我们需要强制执行命名模式。
    它必须遵循包名称
    规则,这意味着必须在
    至少作为您控制的域名,
    您可以创建任意多个子组
    如你所愿。 查看更多信息
    关于包名称

    例如。 org.apache.maven,org.apache.commons

    确定 groupId 粒度的一个好方法是使用
    项目结构。也就是说,如果
    当前项目是一个多模块
    项目,它应该附加一个新的
    父级 groupId 的标识符。

    例如。 org.apache.maven,org.apache.maven.plugins,
    org.apache.maven.reporting

  • artifactId 是没有版本的 jar 的名称。如果你创建了它
    然后你可以选择任何你想要的名字
    想要小写字母,但没有
    奇怪的符号。如果是第三方
    jar 你必须采取的名称
    jar ,因为它是分发的。

    例如。 mavencommons-math

  • 版本如果您分发它,那么您可以选择任何典型的
    带有数字和点的版本(1.0,
    1.1、1.0.1、...)。不要使用日期,因为它们通常与
    快照(每晚)构建。如果它是一个
    第三方神器,你必须使用
    无论它们的版本号是什么,
    看起来很奇怪。

    例如。 2.02.0.11.3.1

Weirdness is highly subjective, I just suggest to follow the official recommendation:

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

傲性难收 2024-10-01 03:18:45

你的约定似乎是合理的。如果我在 Maven 存储库中搜索您的框架,我会在 com.mycompany.awesomeinhouseframework 组目录中查找 awesome-inhouse-framework-xyjar。我会按照你们的约定在那里找到它。

两个简单的规则对我有用:

  • groupId 的反向域包(因为它们非常独特)以及所有 约束将 Java 包名称
  • 项目名称视为 artifactId (请记住,它应该是 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)
凉世弥音 2024-10-01 03:18:45

请考虑以下内容来构建基本的第一个 Maven 应用程序:

groupId

  • com.companyname

artifactId

  • project

<代码>版本

  • 0.0.1

Consider the following for building a basic first Maven application:

groupId

  • com.companyname

artifactId

  • project

version

  • 0.0.1
铁轨上的流浪者 2024-10-01 03:18:45

但是,我不同意 groupId、artifactId 命名约定指南的官方定义,以及建议 groupId 必须以您控制的反向域名开头的版本

com表示该项目属于公司,org表示该项目属于社会组织。这些都可以,但是对于像xxx.tv、xxx.uk、xxx.cn这样奇怪的域名,以“tv.”、“cn.”开头的groupId命名是没有意义的,groupId应该传递基本信息项目的而不是域的。

However, I disagree the official definition of Guide to naming conventions on groupId, artifactId, and version which proposes the groupId must start with a reversed domain name you control.

com means this project belongs to a company, and org means this project belongs to a social organization. These are alright, but for those strange domain like xxx.tv, xxx.uk, xxx.cn, it does not make sense to name the groupId started with "tv.","cn.", the groupId should deliver the basic information of the project rather than the domain.

勿挽旧人 2024-10-01 03:18:45

除了其他之外,我还建议避免将团队名称作为组 ID 的一部分。根据我的经验,项目通常可以在团队之间移动,或者团队可以重命名,因此这不利于识别工件。

In addition to others, I can recommend avoiding team names as part of group ids. From my experience, projects can often move between teams or a team can be renamed, so that's not good for identifying artifacts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文