Hello!
I’ve been struggling to understand this for a while now… and failed. I see some kind of internal resolution mechanism that makes a project with the java plugin applied automatically add constraints from maven pom files down in the dependency tree. It’s best explained on an example. Consider this short project:
plugins {
id("base")
// id("java-library")
}
repositories { mavenCentral() }
configurations { foo }
dependencies {
foo "com.fasterxml.jackson.core:jackson-databind:2.15.2"
foo "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.1"
}
Note the two dependencies with different versions. If you apply the ‘base’ plugin only, configuration foo resolves to (irrelevant details omitted):
foo
+--- com.fasterxml.jackson.core:jackson-databind:2.15.2
| +--- com.fasterxml.jackson.core:jackson-annotations:2.15.2
| | \--- com.fasterxml.jackson:jackson-bom:2.15.2
...
\--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.1
...
However, if you apply the java plugin (and leave everything else as it was), version constraints are imported and added from the jackson-bom subproject, leading to consistent versions everywhere else:
foo
+--- com.fasterxml.jackson.core:jackson-databind:2.15.2
| +--- com.fasterxml.jackson.core:jackson-annotations:2.15.2
| | \--- com.fasterxml.jackson:jackson-bom:2.15.2
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.15.2 (c)
| | +--- com.fasterxml.jackson.core:jackson-core:2.15.2 (c)
| | +--- com.fasterxml.jackson.core:jackson-databind:2.15.2 (c)
| | \--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.2 (c)
...
\--- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.15.1 -> 2.15.2
Note the constraint nodes in the above: “(c)”. I’m puzzled and wonder if somebody could enlighten me as to:
- where is the resolution/ constraint-adding mechanism in gradle code? I’ve been digging through it for hours now but couldn’t find it.
- is it possible at all to configure the base project to add those constraints (without applying the java-library plugin)? I experimented with adding the exact same attributes to the foo configuration which I saw injected by the java plugin but this doesn’t seem related (and in fact causes resolution to fail).
Thank you!