【发布时间】:2022-01-03 14:35:42
【问题描述】:
我有一个项目,其中 log4j-to-slf4j-2.17.1.jar 作为依赖项的一部分自动下载。我也添加了排除标签。但是maven还在下载它。
需要注意的是,我在 pom.xml 的属性标签中指定了 log4j2 版本。它正在下载 log4j-api-2.17.1.jar(这是预期的)以及 log4j-to-slf4j-2.17.1.jar(这不是必需的)。
有什么办法可以解决这个问题吗?请注意,我检查过该 jar 在类路径中也不可用。
pom.xml 中的排除:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.17.1</version>
</exclusion>
</exclusions>
</dependency>
类路径:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
【问题讨论】:
-
dependency.exclusions.exclusion.version不是多余的吗? -
我确实浏览了一些文档和 SO 答案。我看到它在那里被使用。这就是我继续使用它的原因。蓬松你还有其他选择吗?
-
嗯,我不认为有办法不下载它,tbh。
-
这篇描述的 pom sn-p 帖子是完全错误的,因为排除不允许
<version>..</version>标签...除了 log4j-api 不依赖于 log4j-to-slf4j 所以排除根本没有任何意义..此外,如果没有整个依赖关系树,就不可能猜测依赖关系来自哪里...... -
我确实先检查了没有版本标签的 khmarbaise。在确认版本没有版本之后,我只是在添加版本标签时尝试了运气。