79765030

Date: 2025-09-15 10:42:44
Score: 0.5
Natty:
Report link

This is a pretty common gotcha when rebuilding/publishing Spring Framework modules with Gradle. Let’s break down what’s happening and why you’re seeing the warning about missing version for micrometer-observation.


1. Why mavenJava fails but mavenKotlin "works"

By renaming it to mavenKotlin, you avoided the collision, but you also ended up with a stripped-down POM where dependency management didn’t carry over correctly (that’s why micrometer-observation lost its version).


2. Why the POM is missing versions


3. How to fix it (options)

Option A: Keep mavenJava but fix the multi-component issue
Instead of renaming to mavenKotlin, explicitly pick which component to publish:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

Make sure only components.java is used (not components.kotlin or test fixtures).
That way Gradle generates the POM with proper dependency management.


Option B: Use the java plugin correctly (don’t apply kotlin unless you need it)
Right now you have:

apply plugin: "kotlin"

But spring-context itself is not a Kotlin module in the official repo. Adding the Kotlin plugin pulls in components.kotlin → which confuses publishing.
If you don’t actually need Kotlin compilation in spring-context, just remove that line and stick with java.


Option C: Force versions into the POM
If for some reason you want to keep your mavenKotlin publication, you can still inject dependency management into the generated POM:

publishing {
    publications {
        mavenKotlin(MavenPublication) {
            from components.java

            pom {
                withXml {
                    asNode().dependencies.'dependency'.findAll {
                        it.artifactId.text() == 'micrometer-observation' && !it.version
                    }.each {
                        it.appendNode('version', '1.13.5') // or whatever version Spring’s BOM manages
                    }
                }
            }
        }
    }
}

But this is brittle (you’d have to maintain versions manually).


4. Best practice (what Spring does upstream)

If you look at Spring’s official build, they:


🔑 Recommended fix for you


👉 Do you want me to show you exactly how Spring wires dependency-management-plugin into its Gradle build, so you can replicate the same setup and get clean POMs without missing versions?

Reasons:
  • Blacklisted phrase (1): thX
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: The Hungry Androider