首页 文章

如何在多个Maven项目中使用Maven Release Plugin

提问于
浏览
2

我正在使用Maven 3 .

我有多个maven项目,即:'数据模型','服务'和'演示',分为3个不同的项目 . 它们是单独配置的(即不使用maven父pom) .

project setup

我正确地在我的项目上设置maven发布插件,这样当我在每个项目上运行 mvn release:clean release:prepare release:perform 时,它会更新项目版本(即:从3.4.5-SNAPSHOT到3.4.5)以及所有其他内容 .

这里的问题是,“表示”依赖于“服务”依赖于“数据模型”,我指的是带有版本号的pom文件中的项目 .

在我开发的过程中,例如我会将'presentation'中的'service'称为3.4.5-SNAPSHOT . 但是在部署期间,我必须发布'service'来将版本更改为3.4.5,然后我必须在'presentation'中更新我的'service'版本参考,然后才能在'presentation'上运行一个版本 .

是否有自动执行此操作的方法,以便在发布期间不需要更新依赖项目的引用?

由于以下评论我得到了什么:更新:25/03/2013

运行maven:

versions:use-releases -Dmessage="update from snapshot to release" scm:checkin release:clean release:prepare release:perform

结果:版本已更新,但发布版本失败 .

1 回答

  • 3

    Versions Maven Plugin可以帮助您实现要求,尤其是目标versions:use-releases . 您可能对目标versions:use-next-releasesversions:use-latest-releases感兴趣 .

    旁注:

    通常,良好的做法是将它们定义为Maven多模块(herehere) . 这使我们可以更容易地管理版本,如下例所示 .

    父母

    <groupId>my-group</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    
        .....
    
    <modules>
        <module>my-model</module>
        <module>my-service</module>
        <module>my-ui</module>
    </modules>
    

    我的模特

    <parent>
        <groupId>my-group</groupId>
        <artifactId>my-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>my-model</artifactId>
    

    我的服务

    <parent>
        <groupId>my-group</groupId>
        <artifactId>my-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>my-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>my-model</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    

    我的ui

    <parent>
        <groupId>my-group</groupId>
        <artifactId>my-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>my-ui</artifactId>
    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>my-service</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    

    关于上述示例,当我们发布时,相关版本将根据父版本自动更新 .

相关问题