gradlemaven-bom

Publish BOM (as pom.xml) using gradle plugin java-platform


I am setting up a project specific BOM that will "inherit" definitions from other BOMs (available as pom.xml) and also define own managed dependendies.

I tried the following (as stated in the java-platform docs) in my build.gradle.kts:

plugins {
  `java-platform`
  `maven-publish`
}

dependencies {

   constraints {
      api(platform("org.camunda.bpm:camunda-bom:${Versions.camunda}"))
   }
}

publishing {
   publications {
      create<MavenPublication>("camunda-bom") {
          from(components["javaPlatform"])
      }
   }
}

But when I do gradle publishToMavenLocal and check the resulting pom.xml in .m2/repositories it looks like:

<dependencyManagement>
 <dependencies>
   <dependency>
     <groupId>org.camunda.bpm</groupId>
     <artifactId>camunda-bom</artifactId>
     <version>7.10.0</version>
     <scope>compile</scope>
   </dependency>
 </dependencies>

Which will not work because the syntax for importing poms should be

  ...
  <type>pom</type>
  <scope>import</scope>
  ...

How can I publish a valid BOM as pom.xml with gradle (using version 5.3.1)?


Solution

  • You are defining the BOM as a constraint, but that is most likely not what you want to do. A constraint on a platform will just say that if that dependency enters the graph elsewhere it should use the platform part of it and the version recommendation from the constraint.

    If you expect that constraints of that BOM to be visible to the consumers of your platform, then you need to add the BOM as a platform dependency by doing something like:

    javaPlatform {
        allowDependencies()
    }
    dependencies {
        api(platform("org.camunda.bpm:camunda-bom:${Versions.camunda}"))
    }
    

    Then this will be properly published as an inlined BOM in Maven.