18

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?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Maksim Sorokin
  • 2,334
  • 3
  • 34
  • 61

3 Answers3

25

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.

Brett Porter
  • 5,827
  • 27
  • 25
5

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
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
1

You can even go one step further:

-- project
  -- project-module-1
  -- project-module-2

No joking now, this is really a question of taste.

Have a nice day Maksim

Boris Pavlović
  • 63,078
  • 28
  • 122
  • 148
  • 3
    Good suggestion. However, in this naming strategy I would prefer to reserve "-" character for separating nested modules. So "project-module-1" would mean that there is parent project "project", which has a child project "module", which has a child project "1". – Maksim Sorokin Aug 18 '10 at 07:39
  • Then project-module_1 would do the job. – Boris Pavlović Aug 18 '10 at 07:47