[
https://issues.apache.org/jira/browse/LOG4J2-2037?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16159827#comment-16159827
]
Arend v. Reinersdorff commented on LOG4J2-2037:
-----------------------------------------------
Hi [~jvz],
I tried to simplify my use case for this ticket but it ended up incomplete.
Sorry.
You are right, in the most common use case (case 1 below) this works fine. But
in more complicated use cases (cases 2 and 3 below) it would still be nice for
log4j-bom to include slf4j-api.
When only log4-bom is specified in dependency management, consider the
following 3 cases:
{code:xml}
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>2.9.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
{code}
h2. Case 1: log4j-slf4j-impl specified with compile scope
This is probably the most common case. As [~jvz] points out, the correct
version of SLF4J will be used.
{code:xml}
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
</dependencies>
{code}
h2. Case 2: log4j-slf4j-impl specified with runtime scope
This is my actual use case. Code should compile only against slf4j-api. Log4j 2
is only needed at runtime.
The [documentation for Maven Artifacts |
https://logging.apache.org/log4j/2.x/maven-artifacts.html] mentions this:
{quote}Strictly speaking Log4j core is only needed at runtime and not at
compile time.{quote}
But this doesn't work without managing the version of SLF4J by hand as
originally described in this ticket.
{code:xml}
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
{code}
h2. Case 3: Another library used with an slf4j-api dependency
Not my current use case, but probably common as well.
log4j-slf4j-impl is used together with another dependency, which depends on a
possibly different version of slf4j-api, eg spring-ldap-core.
The SLF4J version used depends on the order in which the dependencies are
declared. Which is not so nice.
{code:xml}
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
</dependencies>
{code}
> Include SLF4J in log4j-bom
> --------------------------
>
> Key: LOG4J2-2037
> URL: https://issues.apache.org/jira/browse/LOG4J2-2037
> Project: Log4j 2
> Issue Type: Improvement
> Affects Versions: 2.9.0
> Environment: Maven
> Reporter: Arend v. Reinersdorff
>
> Currently log4j-bom only includes Log4j 2 dependencies. It would be nice
> log4j-bom would also include an slf4j-api dependency (and maybe other
> optional dependencies).
> Currently when using Log4j 2 as a backend for SLF4J the Maven dependency
> management would look like this:
> {code:xml}
> <dependencyManagement>
> <dependencies>
> <dependency>
> <groupId>org.slf4j</groupId>
> <artifactId>slf4j-api</artifactId>
> <version>1.7.25</version> <!-- Must match dependency version
> of log4j-bom -->
> </dependency>
> <dependency>
> <groupId>org.apache.logging.log4j</groupId>
> <artifactId>log4j-bom</artifactId>
> <version>2.9.0</version>
> <type>pom</type>
> <scope>import</scope>
> </dependency>
> </dependencies>
> </dependencyManagement>
> {code}
>
> If log4j-bom would specify a dependency for slf4j-api:
> * Dependency management entry for slf4j-api would no longer be needed
> * Keeping the dependency versions of Log4j 2 and SLF4J in sync would much
> easier. When the dependency version of log4j-bom is increased, it would
> automatically set the dependency version of slf4j-api.
> As an example see [spring-boot-dependencies |
> http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.springframework.boot%22%20AND%20a%3A%22spring-boot-dependencies%22]
> BOM which conveniently specifies many optional Spring Boot dependencies.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)