Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Best Practices for Maven Modules Naming?

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?

like image 256
Maksim Sorokin Avatar asked Aug 18 '10 07:08

Maksim Sorokin


People also ask

How do you name a groupId in Maven?

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.

What should be the artifactId in Maven?

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.

What are modules in Maven?

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.


2 Answers

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.

like image 159
Brett Porter Avatar answered Sep 20 '22 14:09

Brett Porter


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
like image 43
Sean Patrick Floyd Avatar answered Sep 19 '22 14:09

Sean Patrick Floyd