Apache CXF transitive dependencies are missing many dependencies when coming from Maven to Gradle

The problem is, that the CXF authors had the (by many others evaluated as very bad) idea to have a jdk-version activated profile that adds additional dependencies when you build with Java 9+.

But Gradle only supports a small subset of profile activation policies. (If the info in Gradle's Support for Maven POM Profiles ist still correct, then only ones activated by default and ones activated by absence of a system property.)

In this issue I request support for jdk-version activated profiles as the CXF guys are not the only ones doing it that way, they just additionally greatly overuse it by declaring a bunch of dependencies for all artifacts by having the profile in the parent POM: Support for `jdk` activated profiles in POMs · Issue #19224 · gradle/gradle · GitHub
You might want to thumbs-up and subscribe that issue.

In the meantime there are two solutions.
The poor-man’s solution is to just declare those dependencies yourself, e. g. as runtimeOnly as they are not your dependencies.
The ones you use yourself in your code should be declared explicitly anyway instead of bing used transitively.

The semantically better work-around is to use a component metadata rule to fix up the wrong metadata, like this one in the setting script:

dependencyResolutionManagement {
    // work-around for https://github.com/gradle/gradle/issues/19224
    components {
        all {
            if (id.group != "org.apache.cxf") {
                return@all
            }
            check(id.version == "3.5.0") {
                "Please configure Java 9+ dependencies for $id"
            }
            listOf("compile", "runtime").forEach { variant ->
                withVariant(variant) {
                    withDependencies {
                        add("jakarta.annotation:jakarta.annotation-api:1.3.5")
                        add("jakarta.xml.ws:jakarta.xml.ws-api:2.3.3")
                        add("jakarta.jws:jakarta.jws-api:2.1.0")
                        add("jakarta.xml.soap:jakarta.xml.soap-api:1.4.2")
                        add("com.sun.activation:jakarta.activation:1.2.2")
                        add("org.apache.geronimo.specs:geronimo-jta_1.1_spec:1.1.1")
                    }
                }
            }
            withVariant("runtime") {
                withDependencies {
                    add("com.sun.xml.messaging.saaj:saaj-impl:1.5.3")
                }
            }
        }
    }
}
1 Like