I'm an author and a developer focused on build tools. I'm currently focusing on Gradle, but I have an interest in all build tools and most development infrastructure. I focus on Enterprise Java, Ruby, and the interface between Systems Administration and Software Development. The focus of my work is to make it easier for individuals to adopt open source software. Tim is a DZone MVB and is not an employee of DZone and has posted 41 posts at DZone. You can read more from them at their website. View Full User Profile

Maven Tip: Project Directories Should Match the Artifact ID

01.31.2011
| 4997 views |
  • submit to reddit

I almost called this post a Maven “Pet Peeve”, but I’ll stick with “Tip” (and I’ll keep it brief). Here’s a new rule, and I’d really like to hear what the community thinks about this.

Here’s the rule:
Name your project’s directory after the artifactId of your project. It is much easier for everyone to quickly recognize and comprehend multi-module project structure, and it will more closely resemble the experience for developers working with IDEs.
Why do this?

Because it leads to simpler, easier to understand project structure. Some of you might be reading this and asking why we need to remind people of such an obvious rule. Others might take issue with the proposed rule, but I’ll try to detail why I think it is so important. Take the following collection of projects as an example:

Which one do you prefer? Left or right, and why?

On the one hand it is less typing for people on the command line to use simple directory names for Maven modules.

But, on the other hand, if you import these projects with m2eclipse you are going to end up with projects named after the artifactId. The same is true if you import these projects into IntelliJ.

I would suggest always opting for the option on the right. It is clearer than the alternative, and requires less hands-on investigation to track down a culprit project if you are debugging build errors.

An Important Note from Brian Fox: Naming the folder after the artifactId is critical if you expect inherited urls (scm/site) to work. It always appends the artifactId to the url as it’s inherited. And for the same reason, you want them to match what’s in the scm.

From http://www.sonatype.com/people/2011/01/maven-tip-project-directories-and-artifact-ids/

Published at DZone with permission of Tim O'brien, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Collin Fagan replied on Mon, 2011/01/31 - 8:50am

+1, absolutely. I was surprised to find that it worked at all once when I accidentally renamed a folder.

Mladen Girazovski replied on Thu, 2011/02/03 - 7:20am

and I’d really like to hear what the community thinks about this.

I find it importan, maven will still build with mismatching artifact/folder names (except the exceptions you mentioned), but it introduces an additional layer of redirection that would have to be compensated by the developers by mentally mapping artifact ids to folders.

 

But, on the other hand, if you import these projects with m2eclipse you are going to end up with projects named after the artifactId. The same is true if you import these projects into IntelliJ.

One customer not only had complately different folder names than artifact ids, but to make matters worse, some artifact ids were not unique and only the last imported project/pom could be seen in Eclipse as project.

Gabriel Ciuloaica replied on Wed, 2011/02/09 - 10:36am

+1. How about naming the root only "nx" instead of "nx-root" ? I 'm following this strategy for sometime and works good for me.

Thomas Kern replied on Thu, 2012/09/06 - 10:51am

One problem is that artifactIf are unique whereas directory names are supposed not to duplicate their parent names.

For example imagine the following module directory:
platform/core/action

The pom.xml would have an artifactId of platform-core-action

So you'd have a directory of: platform/core/platform-core-action

Which is why I've always hesitated using artifactIds as directory names. I'm tempted to say it's the best solution but I've always had this nagging feeling that it's not a perfect directory name because of the duplication.

I'm curious to hear what others think.

http://www.java-tips.org 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.