-
Notifications
You must be signed in to change notification settings - Fork 816
Potential solution to Maven POM generation issue #4199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| 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
|
||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config.resolvedConfiguration.resolvedArtifactsforces artifact resolution/download just to discover versions and relies on Gradle’s deprecatedresolvedConfigurationAPI. Consider usingconfig.incoming.resolutionResult(orconfig.incoming.dependencies+ResolutionResult) to read selected module versions without artifact downloads and with better forward-compatibility.