ljacomet / logging-capabilities

Apache License 2.0
40 stars 6 forks source link

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

Closed DreierF closed 4 days ago

DreierF commented 1 year ago

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-')
    }
ljacomet commented 1 year ago

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 commented 1 year ago

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 commented 4 days ago

Replaced by: