Java groupid and artifactid

Именование groupId и artifactId

Мой пример: groupId: com.namecompany.nameproject artifactId: nameproject Вопрос: правильно ли такое именование? Если проект включает модули — то artifactId они должны иметь, artifactId:nameprojectNamemodule ?

1 ответ 1

groupId и artifactId могут быть любыми строками (без пробелов). Если вы не планирует распространять свои артефакты используя публичные сервера, то вы вольны поставить туда абсолютно любые значения.

Если вы планирует распространять свои артефакты, то:

  • для groupId рекомендуется использовать такую же схему как и для пакетов в вашем артефакте. Обычно в качестве groupId выбирают имя корневого пакета. Но groupId может отличаться от имен пакетов.
  • для artifactId рекомендуется использовать строку которая описывает содержимое артефакта. Если ваш проект содержит много артефактов, то у них может совпадать groupId.
  • для version рекомендуется использовать цифры разделенные точками (1.0, 2.3). Если это не релиз версия, то в конце добавляют -SNAPSHOT (1.0-SNAPSHOT).

Подобные соглашения нужны для того, что бы maven (и другие системы сборки или системы разрешения зависимостей) мог найти ваши артефакты и добавить их в проект.

Если ваш проект содержит несколько отдельных модулей, то обычно они имеют одинаковый groupId (но это не обязательно) и разные artifactId.

Источник

What is the difference between artifactId and groupId in pom.xml?

How would you explain it to a newbie web developer or programmer with some real world organization example (like say facebook company or Google company)?

I tried to learn it by myself, but I have hard time understanding it. I watched videos, links, few answers in SO, nothing helped. So please help me.

Читайте также:  Разноцветный текст на CSS

It is one of the most common question asked in any software engineering interview. By this question, interviewer wants to know about your basic knowledge on Maven and pom.xml file. I find recently one nice blog post on it with real life example. Just sharing the link here. Hope it will help others. Difference between groupId and artifactId in pom.xml

5 Answers 5

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. eg. maven , commons-math

groupId will identify your project uniquely across all projects, so we need to enforce a naming schema. It has to follow the package name rules, what means that has to be at least as a domain name you control, and you can create as many subgroups as you want. Look at More information about package names. eg. org.apache.maven , org.apache.commons

So lets say my company ABC decided to put my project in internet for public use, the artifactId:, groupId:com.abc.www ? What happens if some one comes up with same name for artifact ID and groupId. There are some probability for that too.

@user3705478 Hm, interesting question. You can try to create a new project using the values for a well known one, and even add it as a dependency, to explore. For example, try «creating» the Apache Commons library: mvn archetype:generate -DgroupId=org.apache.commons -DartifactId=commons-collections4 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false and then add the «real» commons library as a dependency. It appears to work fine. I’m not sure why there is not an occlusion, internally.

When you say a»add it as a dependency» add it to central universal repository or to my local project?

@user3705478 As far as a central repository, you’d have to register your groupId with the provider, and that’s likely where the enforcement happens. For example, if you use Open Source Software Repository Hosting, Sonatype requires you to complete a JIRA ticket with your requested groupId.

Thank you very much for the link. Now I understood better. And I tried creating a second maven project with same artifact ID in my local machine and maven thrown an error.

In case of newbie understanding. This Link describes the best understanding of project identifiers. If I narrow down to main topic then here is the point:

  • groupId – a unique base name of the company or group that created the project
  • artifactId – a unique name of the project

If you want to understand how these identifiers have impact on POM you can visit

  • groupId uniquely identifies your project across all projects.
  • artifactId is the name of the jar without version.

The main difference between groupId and artifactId in Maven is that the groupId specifies the id of the project group while the artifactId specifies the id of the project.

It is required to use third party libraries when developing a project. The programmer can download and add these third-party libraries to the project, but it is difficult to update them later. Maven provides a solution to this issue. It helps to include all the dependencies required for the project. Moreover, the programmer can specify the required dependencies in the POM.XML file. It has the configuration information to build the project. Furthermore, this file consists of several XML elements, and two of them are groupId and artifactId. example groupId : com.test.java (similar to package name) artifactId : javaproject(project or module name)

Источник

Оцените статью