Declare as dependency or as parent

If you have project A and need all the dependencies of project B, do you declare project B the parent of project A, using the inheritance or dependency of project A? They seem to have the same effect.

+6
source share
2 answers

Both approaches differ from each other, one is inheritance, and the other is a simple dependency.

Depending, you will only have binary transitive dependencies of project B.

Using as a parent project, you inherit configurations such as plugins, building model, repositories, dependency management, dependencies, etc., it depends on the case.

My rule for scm configuration, project configuration and development standards or company, I use the parent project (inheritance).

+6
source

I would say that if Project B acts as a “universal parent” or something like what is the starting point for many projects with the same dependencies (or with the same starting point for their dependencies), then go straight ahead and do B parent .

Otherwise, if in fact it is more likely a “convenient thing”, for example, she received methods like “utilities / main type”, which many projects find useful , but do not rely on their existence , then this is logically dependent.

You can even consider splitting Project B into two along these lines. This is what I have done in the past:

mygroup-parent is a project consisting entirely of a POM file with dependencies, which I want so that every project can get a standard approach. For example, I have TestNG and Mockito .

mygroup-core is a full-fledged Java project in which there are useful things that are often used, but are not required. I have helper methods for things specific to my site and for dependencies like Apache HttpClient and Google Guava .

+8
source

Source: https://habr.com/ru/post/906254/


All Articles