javamavenpom.xmlslf4jmaven-dependency

NoSuchMethod org.slf4j.spi.LocationAwareLogger error


I'm facing with NoSuchMethod org.slf4j.spi.LocationAwareLogger erro in my code after typing mvn clean test command through cmd.

Probably it's related to maven dependency but i couldn't figure out where i should exactly arrange in pom xml.

 <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.30</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.25</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.7.25</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-nop</artifactId>
    <version>1.7.25</version>
    <scope>test</scope>
</dependency>

In addition, i tried to check dependency tree by using mvn dependency:tree but it didn't come to meaningful.

enter image description here


Solution

  • Use mvn dependency:tree to see which version of slf4j maven decides to give you. If it has picked the wrong version, you could use a dependency management section to specify which version you want. And you need to add exclusion to pom to dependacy you dont use.

    In addition, another way to fix if using Eclipse IDE, use SHIFT + CTRL + T to open following type "SLF4JLocationAwareLog" You should be able to find related library and so a potential conflict. Switch to the dependency tree view of the pom.xml to know the exclusion to add.