且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Maven中从父项目中排除依赖项?

更新时间:2022-06-12 22:19:52

我认为在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.