Assuming that we have a project named project
and modules module1
and module2
, earlier I tend to use the following naming strategy:
-- project
-- projectModule1
-- projectModule2
Now I use another:
-- project
-- project-module1
-- project-module2
What are best practices for Maven modules naming?
Look at More information about package names. 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. artifactId is the name of the jar without version.
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.
A Maven module is a sub-project. To create a Maven module you will need to already have a Maven project available. The parent project must have its Packaging option pre-configured to pom, for a module to be created and associated with it.
I wrote some notes on this in the "Effective Implementation" book, but there is no rule or canonical convention.
To summarise some:
First of all, the most important things is that you are consistent.
General Maven convention uses '-' as the separator (commons-lang
, maven-model
).
If you intend for it to be used externally, remember the module = artifact ID = filename
(in best practice), so it needs to be recognisable (maven-model-2.0.jar
is clear, model-2.0.jar
is not). In this case, you usually repeat the last element of the group ID as a mini-namespace. "Internal" modules may omit it for brevity (As the example application shows: http://github.com/brettporter/centrepoint/tree/master/centrepoint/modules/).
Aside from that, I'd keep them as short as possible.
You might draw the parallel between Java package and class naming conventions to Maven group and artifact IDs.
I usually try to keep module names brief. If the name 'wants' to be long, that's an indication that another nesting level is probably a good idea. So instead of this:
- root
- api
- impl
- security
- service-soap
- service-rest
- client-swing
- client-web-html
- client-web-mobile
I'd nest things further:
- root
- api
- impl
- security
- service
- soap
- rest
- client
- swing
- web
- html
- mobile
through maven reactor options you can still build the nested modules isolated from the top:
mvn -pl client/web clean install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With