MAVEN 与 JAVA 包命名规范

抛出问题

在使用MAVEN搭建模块化项目时,我的组织结构如下:

  1. root模块

文件夹名:package-module-project

pom.xml文件:

<project><groupId>com.chuillusion</groupId><artifactId>chuillusion-package</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><modules><module>chuillusionCore</module><module>chuillusionBrowser</module><module>chuillusionApp</module><module>chuillusionDemo</module></modules>
</project>
  1. 子模块

2.1 核心模块
文件夹名:chuillusionCore

pom.xml文件:

<project><parent><artifactId>chuillusion-package</artifactId><groupId>com.chuillusion</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>chuillusion.core</artifactId>
</project>

Java包命名:com.chuillusion.cores为根包

存在问题

  1. 项目文件夹命名与maven中artifactId不一致

root模块项目命名为package-module-project,root所对应的artifactId命名为chuillusion-package

  1. java包命名与maven不一致

核心模块中java根包命名为:com.chuillusion.cores,核心项目中artifactId命名为chuillusion.core

  1. idea显示不一致

当项目名称与artifactId不一致时,idea则会在项目名则展示artifactId

如:chuillusionCore[chuillusion.core] ,即:项目名[artifactId]

命名规则探讨

  1. 官网说明

参考MAVEN官方文档中的命名规范

Guide to naming conventions on groupId, artifactId and version

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

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

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

  1. 以驱动包案例分析
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.43</version>
</dependency>

生成的包名称为:mysql:mysql-connector-java-5.1.43.jar,即为groupId:artifactId-version.jar

源码结构:com.mysql作为项目根包

疑问:个人感觉是没有按照规范进行命名的

  1. assertj分析
<dependency><groupId>org.assertj</groupId><artifactId>assertj-core</artifactId><version>3.8.0</version>
</dependency>

源码结构:org.assertj.core作为根包

  1. logback分析
<dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.3.0-alpha3</version><scope>test</scope>
</dependency>

源码结构:ch.qos.logback.classic作为根包

  1. 结论

1)源码包中需要有groupId开头,紧接artifactId作为根包

规范命名

养成良好的编码习惯,从命名规范做起

修改项目命名

项目名与artifactId相对应,源码目录与整体结构对应

  1. root模块

项目名称:package-module-project

<project><groupId>com.chuillusion</groupId><artifactId>package-module-project</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><modules><module>chuillusion-core</module><module>chuillusion-browser</module><module>chuillusion-app</module><module>chuillusion-demo</module></modules>
</project>

root项目为空结构,只有一个pom文件负责管理子模块,因此没有源码目录结构

  1. 核心模块修改

修改方式一:

项目名称:chuillusion-core

<project><parent><artifactId>package-module-project</artifactId><groupId>com.chuillusion</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>chuillusion-core</artifactId>
</project>

源码根目录结构:com.chuillusion.core

修改方式二

项目名称:core

<project><parent><artifactId>package-module-project</artifactId><groupId>com.chuillusion</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>core</artifactId>
</project>

源码根目录结构:com.chuillusion.core

说明

写这篇文章是因为1)项目中遇到的问题;2)在baidu上没有相关文章

欢迎各位留言指正文章的错误,谢谢!

---------------------
作者:楚丶迷梦
来源:CSDN
原文:https://blog.csdn.net/sinat_30254575/article/details/79735051
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件

[转]maven与java命名规则相关推荐

  1. java命名规则_Java命名规则

    Java命名规则 定义规范的目的是为了使项目的代码样式统一,使程序有良好的可读性. 命名规则: java源文件的命名 如果有public类,那么源文件名就是public类名,一个文件中只能有一个pub ...

  2. java命名规范怎么定义?java命名规则

    在java刚刚入门时,我们可能首先就要了解java中一些常规的命名规范了,这也是必要的,否则当你以数字开头作为类名,都不知道为啥会报错.我们一起来看看,java命名规范是怎么定义呢?java命名规则和 ...

  3. java命名规则与规范

    标识符的使用 1.标识符:凡是自己可以起名字的地方都叫标识符. 比如:类名.变量名.方法名.接口名.包名- 2.标识符的命名规则: -->如果不遵守如下的规则,编译不通过!需要大家严格遵守 ①由 ...

  4. Java命名规则和Java命名规范

    Java的命名规则 允许有下划线,数字,字母,$组成 数字不能作为开头 不能是关键字可以包含关键字 区分大小写 不能是true,false和null关键字 Java命名规范 常量,都大写,如果是多单词 ...

  5. java命名规则与命名规范

    标识符命名规则 在我们编写的程序中,我们所使用的变量名.类名.方法名等自定义的名称都叫做标识符 在java中,标识符中可以包含字母.数字以及下划线和 $ 符号等等 标识符不能以数字开头,也不能是关键字 ...

  6. Java命名规则及规约

    1.命名规则: 可以用字母.数字.字符以及中文命名: 字母需要区分大小写: 数字不可以放在开头首位: 字符可以用的只有:_ $: 不推荐使用中文命名: 2.命名规约: 类名:首字母大写,两个单词及以上 ...

  7. java 全局变量 命名规则_Java 基础 运算符 命名规则 变量 循环

    1.程序: 一组指示计算机执行行动或坐车判断的指令,通常用某种程序设计语言编写,运行于某种目标体系结构上. 2.软件 与计算机操作系统有关的计算机程序,规程.规则,以及可能有的文件,文档及数据 3.软 ...

  8. Java中类、常量、变量、方法名等命名规则

    Java中类.常量.变量.方法名等命名规则 命名规则: 命名由字母.数字.下划线.美元符号($)构成. 命名不可以数字作为开头. 长度无限制,但不可存在空格. 大小写所表述内容含义不同. 命名不可与J ...

  9. Java中包、类、方法、属性、常量的命名规则

    1:包(package):用于将完成不同功能的类分门别类,放在不同的目录(包)下, 包的命名规则:对于包名:每个字母都需要小写. 将公司域名反转作为包名.比如www.baidu.com 比如:com. ...

最新文章

  1. 50道mysql笔试题目及答案_50道SQL练习题及答案与详细分析!!!
  2. check your cluster UI to ensure that workers are registered and have sufficient resources
  3. P6091-[模板]原根
  4. 你好,C++(34)有一只叫做多利的羊 6.2.4 拷贝构造函数
  5. Android应用开发—知识点汇总
  6. 三种方法构建简单的WEB服务器!
  7. C语言课后习题(38)
  8. JetBrains IDEA实用快捷键
  9. python lxml用法详解_Python-- lxml用法
  10. mybatis 学习五 二级缓存不推荐使用
  11. 从0开始学习 GitHub 系列之「05.Git 进阶」
  12. mysql导入.sql文件中文乱码_mysql通过sql文件导入数据时出现乱码的解决办法
  13. 这些年,这些ACM大佬-施韩原访谈
  14. leadbbs移花接木漏洞与加入黑客木马
  15. 官方win10安装教程,win10系统一键安装方法
  16. zookeeper启动报错:JMX enabled by default,服务未启动
  17. 在存储过程中调用外部对象进行简繁互换
  18. 闹钟和时间管理工具Alarm Clock Pro mac
  19. 程序员的贫富两极分化,穷的穷死,富的富死,我就是那“穷鬼”?
  20. 网页整体放大/缩小的实现

热门文章

  1. 如何添加自定义icon
  2. 承接数字油画图稿/线条图定制(出图)业务
  3. 博客园程序源代码下载
  4. C#多线程开发-使用并发集合
  5. 【另类见解】一致性哈希就能解决分库分表问题了?
  6. 快醒醒,C# 9 中又来了一堆关键词 init,record,with
  7. 微服务统计,分析,图表,监控一体化的HttpReports项目在.Net Core 中的使用
  8. Blazor 版 Bootstrap Admin 通用后台权限管理框架
  9. 花5分钟时间来了解一下高性能网关Kong会有意外收获
  10. 从SQL Server到多数据库,微软数据库迁移全攻略