Issue
I have a project where log4j-to-slf4j-2.17.1.jar is automatically downloading as a part of dependency. I have added the exclusions tag as well. But still maven is downloading it.
To note that, I have specified the log4j2 version in the properties tag of the pom.xml. And it is downloading log4j-api-2.17.1.jar(which is expected) as well log4j-to-slf4j-2.17.1.jar(which is not required).
Any work arounds to resolve this? Please note that, I have checked to see that the jar is not available in classpath as well.
Exclusion in 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>
Classpath:
<?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>
Solution
log4j-api
doesn't depends on log4j-to-slf4j
so adding exclusion in log4j-api
don't do anything.
Use mvn dependency:tree
and check which direct dependency brings log4j-to-slf4j
as transitive dependency then add exclusion there, also version is not required in exclusion since there will be only one version as dependency to an artifact.
Answered By - Karthikeyan Vaithilingam
Answer Checked By - Marie Seifert (JavaFixing Admin)