logging-capabilities icon indicating copy to clipboard operation
logging-capabilities copied to clipboard

Enforcing Log4J2 with commons-logging dependencies does not resolve to log4j-jcl

Open DreierF opened this issue 1 year ago • 2 comments

When enforcing Log4J2 with a dependency that uses commons-logging the final result does not resolve to log4j-jcl. The current behavior also results into runtime errors. Only when manually adding log4j-jcl the issue is gone.

Might also be that I'm missing something as I'm not really deep into logging.

Failing test:

    @Unroll
    def "enforcing log4j2 with jcl"() {
        given:
        withBuildScript("""
            plugins {
                `java-library`
                id("dev.jacomet.logging-capabilities")
            }

            repositories {
                mavenCentral()
            }
            
            loggingCapabilities {
                enforceLog4J2()
            }
            
            dependencies {
                implementation("org.slf4j:slf4j-api:1.7.27")
                implementation("org.apache.logging.log4j:log4j-api:2.12.1")
                implementation("org.apache.logging.log4j:log4j-core:2.19.0")
                implementation("commons-logging:commons-logging:1.2")
                runtimeOnly("org.slf4j:jcl-over-slf4j:1.7.27")
            }

            tasks.register("doIt") {
                doLast {
                    println(configurations["runtimeClasspath"].files)
                }
            }
""")
        when:
        def result = build(['doIt'])

        then:
        outcomeOf(result, ':doIt') == SUCCESS
        result.output.contains('log4j-jcl-')
    }

DreierF avatar Apr 01 '23 16:04 DreierF

Thank you for your interest in this plugin.

As indicated in the docs, this plugin does not add dependencies. And for Gradle to detect a capability conflict, it must see more than one dependency with the capability.

So you need to make sure that org.apache.logging.log4j:log4j-jcl is in the dependency graph.

If I add the following to your test, it passes:

implementation("org.apache.logging.log4j:log4j-jcl:2.19.0")

ljacomet avatar Apr 22 '23 15:04 ljacomet

Actually, I am wrong. Looks like when I worked on the different enforce*, I left out declaring the substitutions for enforcing Log4J2.

I'll see about adding those, so that the behavior matches what's done for Logback and Slf4J simple.

ljacomet avatar Apr 22 '23 15:04 ljacomet

Replaced by:

  • gradlex-org/jvm-dependency-conflict-resolution#163

ljacomet avatar Sep 08 '24 13:09 ljacomet