user496949
user496949

Reputation: 86085

Maven groupId and package name in java source

If I have a maven groupid com.mycompany.app, does it mean I need to name my package under the name of com.mycompany.app.*?

Upvotes: 22

Views: 15937

Answers (2)

user3747182
user3747182

Reputation: 381

While creating a maven project if you have mentioned values for both groupId and package name, then maven will consider the package name to place your java class.

For example:

mvn archetype:generate -DgroupId=gen.src -DartifactId=Iftekhar -DpackageName=com.src.Model -Dversion=2.0-Snapshot

In the above scenario App.java class will be created inside the package com.src.Model and the groupId value will not be considered.

But if you have mentioned only groupId value (and not package name) like below:

mvn archetype:generate -DgroupId=com.src.Controller -DartifactId=Iftekhar -Dversion=2.0-Snapshot  

Then App.java class will be created inside the package com.src.Controller.

Upvotes: 5

tgdavies
tgdavies

Reputation: 11421

No, maven doesn't care what package names you use. Having said that, it's not a bad idea to make them consistent to make it a little easier to see which dependency a class comes from.

Upvotes: 36

Related Questions