Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions gradle/maven/defaults-maven.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,34 @@ configure(subprojects.findAll {it.path in rootProject.published}) {prj ->
}
}
}

// Resolve actual dependency versions for any <dependency> entries with missing
// <version>. This handles BOM-managed dependencies (e.g. Jackson) whose versions
// are resolved by Gradle but not written into the generated POM, which causes
// "missing version" errors for Maven consumers.
def resolvedVersions = [:]
['compileClasspath', 'runtimeClasspath'].each { configName ->
def config = prj.configurations.findByName(configName)
if (config) {
config.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def id = artifact.moduleVersion.id
def key = "${id.group}:${id.name}"
if (!resolvedVersions.containsKey(key)) {
resolvedVersions[key] = id.version
Comment on lines +191 to +195
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.resolvedConfiguration.resolvedArtifacts forces artifact resolution/download just to discover versions and relies on Gradle’s deprecated resolvedConfiguration API. Consider using config.incoming.resolutionResult (or config.incoming.dependencies + ResolutionResult) to read selected module versions without artifact downloads and with better forward-compatibility.

Suggested change
config.resolvedConfiguration.resolvedArtifacts.each { artifact ->
def id = artifact.moduleVersion.id
def key = "${id.group}:${id.name}"
if (!resolvedVersions.containsKey(key)) {
resolvedVersions[key] = id.version
def resolutionResult = config.incoming.resolutionResult
resolutionResult.allComponents.each { component ->
def id = component.id
if (id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier) {
def key = "${id.group}:${id.module}"
if (!resolvedVersions.containsKey(key)) {
resolvedVersions[key] = id.version
}

Copilot uses AI. Check for mistakes.
}
}
}
}
root.dependencies?.dependency?.each { dep ->
def versionNodes = dep.version
if (!versionNodes || !versionNodes.text()) {
def key = "${dep.groupId.text()}:${dep.artifactId.text()}"
def resolvedVersion = resolvedVersions[key]
if (resolvedVersion) {
dep.appendNode('version', resolvedVersion)
}
}
Comment on lines +200 to +208
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a dependency is missing <version> and resolvedVersions doesn’t contain a match, the POM will remain invalid but publishing will still succeed. It would be safer to fail the build (or at least log a warning/error) when a missing version can’t be resolved, so broken POMs aren’t published silently.

Copilot uses AI. Check for mistakes.
}
}
}
}
Expand Down
Loading