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

江枫思渺然 提交于 2020-06-29 08:05:11

问题


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 publishToLocalMaven 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)?


回答1:


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.



来源:https://stackoverflow.com/questions/55687995/publish-bom-as-pom-xml-using-gradle-plugin-java-platform

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!