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:
Thanks so much! I was already suspecting, that Apache CXF does something strange and out of the ordinary. Currently, I added my missing dependencies manually (workaround #1) but your script, as I understand it, basically does the same work manually, but also checks to make sure that if the version 3.5.0 is ever touched, I get a message, asking for updating the dependency fix. Is that right?
Currently, my only way to find what is actually missing is to also have a working maven build ready to run. But I wanted to get rid of this. How can I make sure to manually get to the missing dependencies once the version is raised? Is there a better way?
It basically also adds the deps manually, yes.
But it adds them to the proper variants, so is semantically better.
And yes, it will yell at you if you update the version to double-check the work-around versions.
You can simply look at that cxf-parent POM at https://repo1.maven.org/maven2/org/apache/cxf/cxf-parent/3.5.0/cxf-parent-3.5.0.pom, there you find a jdk-activated profile that adds the dependencies. There you can find the versions (or the properties from which the version can be read and the scope. Add all compile (or default) scoped to compile and runtime variant and all runtime scoped like saaj-impl to runtime variant.
You can also put it in the build script if you want, you just have to put it into a different container then.
But I would do it in the setting script, yes.
Is there one more trick to make it work…? It compiles fine in settings.gradle.kts - but it does not do anything.
I added a println(“In $id now”) right before the if (id.group != “org.apache.cxf”) check - and during build it only ever is there twice, printing:
Do you have it in the correct settings script?
Did you actually try to resolve the configuration or just do something like ./gradlew help?
Actually I wonder where you got that gradle:gradle:7.4 dependency from, never seen that.
Oha. Now we have differences in IntelliJ Gradle and “normal” gradlew execution!
I have the correct settings.gradle.kts in my project’s root. (There is no other settings file of that kind anywhere). I added your snippet and pressed the IntelliJ button to reload Gradle which pops up when anything in the build settings is changed.
Then, in the Build tab of IntelliJ you see the two gradle:gradle:7.4 outputs… And looking at my dependency tree in the Gradle tab, nothing has changed regarding CXF.
BUT: on the command line, executing gradlew build works exactly like promised: you see all my dependencies printed as I expected!
Why does having ONE problem always lead to new problems…?
Just to try this: what container do I have to put this in to make it work in build.gradle.kts? And why is the settings the right place? Basically: what context does this method “dependencyResolutionManagement” need to be found?
As to why in the setting script, I like to do things in the central place that can be done there. This way it automatically is there for all projects where this dependency might also be added in the future without the chance to forget it.
You really went the same path of problems I am facing… Incredible. Thanks so much. I owe you a beer…
BTW: opened a bug at JetBrains… minutes before I read your answer… https://youtrack.jetbrains.com/issue/IDEA-289795