maven - 传递依赖[复制](maven - transitive dependencies [duplicate])

这个问题在这里已经有了答案:

Maven:我应该保留还是移除也是传递依赖项的声明的依赖项? 2个答案

我在pom.xml中定义数据时尝试遵循最佳实践,所以我开始研究Spring源代码,我看到:

<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId&gtorg.springframework</groupId> <artifactId&gtspring-aop</artifactId> <packaging&gtjar</packaging> <version&gt3.1.1.RELEASE</version> ..... <dependency> <groupId&gtorg.springframework</groupId> <artifactId&gtspring-beans</artifactId> <version>${project.version}</version> <scope&gtcompile</scope> </dependency> --- <dependency> <groupId&gtlog4j</groupId> <artifactId>log4j</artifactId> <scope&gttest</scope> </dependency> -----

但是,spring-beans也依赖于log4j。

你能告诉我,最佳实践方法,你应该在多大程度上依赖传递性依赖?

我问这个是因为我的第一个想法是不重新声明log4j依赖,因为spring-beans已经声明了它。

This question already has an answer here:

Maven : Should I keep or remove declared dependencies that are also transitives dependencies? 2 answers

I am trying to follow best practices when defining data in pom.xml, so I started to look into the Spring source code, and I have seen:

<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <groupId&gtorg.springframework</groupId> <artifactId&gtspring-aop</artifactId> <packaging&gtjar</packaging> <version&gt3.1.1.RELEASE</version> ..... <dependency> <groupId&gtorg.springframework</groupId> <artifactId&gtspring-beans</artifactId> <version>${project.version}</version> <scope&gtcompile</scope> </dependency> --- <dependency> <groupId&gtlog4j</groupId> <artifactId>log4j</artifactId> <scope&gttest</scope> </dependency> -----

But, spring-beans also has a dependency on log4j.

Can you please tell me, for the best practice methods, on what extent should you rely on transitive dependencies?

I am asking this because my first thought was not to redeclare the log4j dependency, since spring-beans had already declared it.

最满意答案

声明您明确依赖的依赖项,它是否提供您直接导入和使用的类,或者它是提供您直接使用的服务的东西,如Log4J。 传递依赖只应该提供运行时需要的依赖关系,但不要使用自己。

Declare dependencies that you explicitly rely on, whether it provides classes you directly import and use or it's something that provides a service you directly use, like Log4J. Transitive dependencies should only supply dependencies that are needed at runtime but that you don't use yourself.

更多推荐