我有一個專案,其中 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>
uj5u.com熱心網友回復:
log4j-api不依賴于log4j-to-slf4j所以添加排除在log4j-api不做任何事情。
使用mvn dependency:tree并檢查哪個直接依賴項log4j-to-slf4j作為傳遞依賴項帶來,然后在其中添加排除項,排除項中也不需要版本,因為只有一個版本作為對工件的依賴項。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/405484.html
標籤:
