Given three project modules X, Y and Z on a Maven based project, and Y depends of Z and X of Y and X should not know that Y depends of Z, being this:

X -> Y

Y -> Z

X -X> Z

What is the best way to hide the dependency between modules X and Z ?

I'm aware that on Maven it's possible to change the scope of the dependency, but I would like to know if there are any other options for it

  • What do you mean by X not knowing about the dependency between Y and Z? Should the fact that Z exists be completely hidden from users/developers of X, or do you just want to avoid having to declare a dependency between X and Z, something else? – Bart van Ingen Schenau Aug 17 at 10:27
  • Users/Developers of X should not know about Z existence @BartvanIngenSchenau – SEISCOOL Aug 17 at 10:30
  • What is the relationship between Y and Z? Is Z just needed to build Y, or does the produced Y.jar also depend on Z.jar to be able to execute? – Bart van Ingen Schenau Aug 17 at 10:37
  • Y depends in any form of Z, as an example we can say that Z is the core of the project We could say Y is the application controller and X is the front-end – SEISCOOL Aug 17 at 10:39
  • Then you are probably out of luck. You can't hide the existence of Z, because of the simple fact that if it is missing from the installation, then the application won't work. – Bart van Ingen Schenau Aug 17 at 10:44

You do not want the programmers of X to use classes of Z. You can achieve this with the Maven dependency plugin:

https://maven.apache.org/plugins/maven-dependency-plugin/analyze-only-mojo.html

This allows you to fail the build if somebody uses a class from an artifact that is not declared as dependency in their own POM.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.