How to depend on log4j in a Sonarqube plugin?

723 views Asked by At

I am developing a SonarQube 5.6 plugin. This plugin depends on a library X (a third party library). Library X depends on Log4J. To resolve the dependency problem I am adding log4j dependency in pom.xml with provided scope as defined in SonarQube documentation. But at runtime I am getting class not found exceptions related to log4j.

When I change my third party library, so that it does not use log4j anymore (basically log4j related code is commented out), the problem is gone.

How should I add the log4j dependency in SonarQube or what should I do so that the problem with log4j is resolved in my SonarQube plugin? Or what is the best way to deal with such problem when container says it will provide the dependency but it is not?

The dependency is declared like this:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.8.2</version>
</dependency>
1

There are 1 answers

1
Julien H. - SonarSource Team On

You should exclude any log4j dependency, and instead rely on log4j-over-slf4j to redirect any log4j call to slf4j.

log4j-over-slf4j should be already provided in the runtime plugin classloader, so basically it should work out of the box. What kind of problem are you facing?