我们如何在同一个 pom 中构建和引用 bom

How can we build and refer bom in same pom

我有一份构建父 pom 的 jenkins 工作。在父 pom 中,我也有一个模块 BOM。 bom 本身在同一个父 POM 中被引用,如下所示。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.org.fgn.abs</groupId>
            <artifactId>abs-bom</artifactId>
            <version>${project.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies> 
</dependencyManagement>

但是找不到正确版本的bom。很明显它不会找到 bom,因为它还没有构建。 我只是在寻找任何方法来做同样的事情,而无需单独的工作来构建 bom。

提前致谢。

而不是使用 <版本>${project.version}

尝试提供明确的版本,例如,

<版本>0.0.1-SNAPSHOT

您可以参考 http://www.baeldung.com/spring-maven-bom

是的,问得好。一个选择肯定是,您可以首先使用 Jenkins 中的单独作业构建 BOM 项目,这样当您构建主父项目时,它会发现该依赖项。我确实以这种方式配置了一些项目,它应该可以正常工作。 我认为的另一种选择是您可以将 BOM 项目作为另一个父项目中的一个模块,比如 B,然后将这个父项目作为一个模块包含在您的主父项目中。老实说,我还没有尝试过第二种方法,但你可以尝试一下。

HTH

此问题的一个解决方案是像您一样将 BOM 添加为模块,但要确保它是要构建的第一个模块。

<modules>
    <!-- Run first, not using the parent but part of the aggregator -->
    <module>bom</module>
    <!-- Module 1 using the parent -->
    <module>module1</module>
    <!-- Module 2 using the parent, depends on module 1 -->
    <module>module2</module>
</modules>

可以在 https://github.com/anliksim/maven-template-bom.

找到一个简单而优秀的代码示例

确保阅读关于 versions-maven-plugin 的备注(如果您正在使用它)并使用 processAllModules.

mvn versions:set -DnewVersion=1.1-SNAPSHOT -DprocessAllModules=true