Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between package and groupId in maven

Tags:

java

maven

I understand the terms, groupId, artifactId and version. While reading about package, I can see it is The name of your root package. The default is the groupId you entered before..

In that case, what is the difference between package and groupId? I guess its always the same, or if they can be different than how? Someone explain

enter image description here

like image 530
Muhammad Tahir Qaiser Avatar asked Dec 23 '22 20:12

Muhammad Tahir Qaiser


1 Answers

Seems like you are asking what does package means when using Maven Archetype to generate a new Maven project.

The package is to configure the root java package that contains all the generated source codes. So if you set the package to com.foo.bar , the generated project will contain a folder com/foo/bar/ in /src/main/java.

groupId , together with artifactId and version is a kind of an unique identifier of your library . That means after you package your project as a JAR and publish it to the world , other developers can import it to their project to use by specifying the correct groupId , artifactId and version in their pom.xml.

So , the package is just the internal root package used by your project internally and it will not affect how developer locates and import your JAR to their project. The package and the groupId can be different.

(But of course, you are supposed to name the package to some unique name such that it does not conflict with other well-known libraries (e.g. don't name it as java.lang or org.springframework etc.)

like image 103
Ken Chan Avatar answered Feb 19 '23 02:02

Ken Chan