使用gradle插件Java平台发布BOM(作为pom.xml) [英] Publish BOM (as pom.xml) using gradle plugin java-platform

查看:584
本文介绍了使用gradle插件Java平台发布BOM(作为pom.xml)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设置一个项目特定的BOM,它将继承"其他BOM的定义(可从pom.xml获得),并且还定义自己的托管依赖项.

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.

我尝试了以下操作(如 java平台文档所述)在我的build.gradle.kts中:

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"])
      }
   }
}

但是当我执行gradle publishToLocalMaven并在.m2/repositories中检查生成的pom.xml时,它看起来像:

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>

这将不起作用,因为导入pom的语法应为

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

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

如何使用gradle(使用5.3.1版)将有效的BOM发布为pom.xml?

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

推荐答案

您正在将BOM表定义为constraint,但这很可能不是您想要的. 平台上的约束条件只是说,如果该依赖关系进入图形 elsewhere ,则应使用其中的platform部分以及该约束条件的版本推荐.

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.

如果您希望该BOM的约束对于您的平台使用者可见,那么您需要通过执行以下操作将BOM作为platform dependency添加:

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}"))
}

然后将其作为内嵌BOM正确发布在Maven中.

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

这篇关于使用gradle插件Java平台发布BOM(作为pom.xml)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆