如何在Maven中从父项目中排除依赖项?
例如,我有2个Maven项目。一个是项目 - 父母。另一个是项目孩子。显然,项目 - 孩子是项目 - 父母的子项目。
For example, I have 2 Maven projects. One is "project-parent". The other is "project-child". Obviously, "project-child" is the sub project of "project-parent".
project-parent具有log4j的依赖关系。但我想将它从项目 - 孩子中排除。有办法吗?
"project-parent" has a dependency of log4j. But I want to exclude it from the "project-child". Is there a way?
您可能会说我应该将log4j从project-parent移动到project-child。这是完全正确的。 但假设我不能修改项目父母的POM。
You might say I should move log4j from "project-parent" to "project-child". That is totally correct. But the assumption is I CANNOT modify "project-parent"'s POM.
提前致谢。
我认为在Maven2中没有办法实现这一点,因为这是POM继承的
。但是我可以想到一个技巧:
I think in Maven2 there is no way to achieve this, because this is what POM inheritance is for . However there is one trick that I can think of:
假设您有权将工件上传到内部工件存储库。您可以创建一个空的JAR,将其部署为log4j:log4j,具有明显异常的版本(例如log4j:log4j:9999)。在project-child中添加这样的依赖项。然后它将覆盖parent的依赖关系取决于实际上为空的JAR。
Assume you have the right to upload artifact to your internal artifact repository. You may create an empty JAR, deploy it as log4j:log4j, with a obviously abnormal version (e.g. log4j:log4j:9999 ). Add such dependency in your project-child. Then it will override the dependency of parent to depends on a in-fact-empty JAR.