简体   繁体   English

如何发布具有未发布依赖项的多模块项目

[英]How to release a multi-module project with non released dependencies

I have a multi module project (flat structure) as follows 我有一个多模块项目(扁平结构)如下

parentpom (1.1-SNAPSHOT)
moduleA (inherits parentpom version, depends on moduleB(1.1-SNAPSHOT))
moduleB (inherits parentpom version)
aggregator (inherits parentpom version, aggregates moduleA, moduleB)

The aggregator allows me to build, install and deploy moduleA and moduleB at the same time, and appears to do what I expect. 聚合器允许我同时构建,安装和部署moduleA和moduleB,并且看起来像我期望的那样。

When I try and do a release of version 1.1, I can't because moduleA depends on moduleB(1.1-SNAPSHOT), resulting in the following error: "Can't release project due to non released dependencies" 当我尝试发布1.1版时,我不能,因为moduleA依赖于moduleB(1.1-SNAPSHOT),导致以下错误:“由于未发布的依赖项而无法释放项目”

I thought that using the aggregator would allow me to do a "synchronised" release of moduleA and moduleB, automatically updating moduleA to depend on moduleB(1.1). 我认为使用聚合器将允许我对moduleA和moduleB进行“同步”发布,自动更新moduleA以依赖于moduleB(1.1)。 What would be the correct way of achieving this? 实现这一目标的正确方法是什么?

Thanks 谢谢

How to release a multi-module project with non released dependencies 如何发布具有未发布依赖项的多模块项目

To strictly answer this question, this is not possible, at least not with the Maven Release Plugin. 要严格回答这个问题,这是不可能的,至少不能使用Maven Release Plugin。 And if you don't use the Maven Release Plugin and do the release manually, you should not do that anyway. 如果您不使用Maven Release Plugin并手动执行发布,则无论如何都不应该这样做。

Reason: the build of a released should be repeatable, building it later from its sources should give the exact same reasult. 原因:释放的构建应该是可重复的,稍后从其来源构建它应该给出完全相同的结果。 Having some SNAPSHOT dependencies in some released POM totally defeats this goal. 在一些发布的POM中有一些SNAPSHOT依赖完全违背了这个目标。 Which is why the Maven Release Plugin enforces this. 这就是Maven Release Plugin强制执行此操作的原因。

I thought that using the aggregator would allow me to do a "synchronised" release of moduleA and moduleB, automatically updating moduleA to depend on moduleB(1.1). 我认为使用聚合器将允许我对moduleA和moduleB进行“同步”发布,自动更新moduleA以依赖于moduleB(1.1)。 What would be the correct way of achieving this? 实现这一目标的正确方法是什么?

Are the versions hard coded? 版本是否经过硬编码? If they are, this might be the problem. 如果是,那可能就是问题所在。

  • moduleB and moduleA shouldn't declare any version, they inherit it from the parent POM moduleB和moduleA不应声明任何版本,它们从父POM继承它

  • moduleA should use the built-in properties to declare its dependency on B moduleA应该使用内置属性来声明它对B的依赖

     <dependency> <groupId>${project.groupId}</groupId> <artifactId>moduleB</artifactId> <version>${project.version}</version> </dependency> 

I ran into a similar a problem and the first answer in this thread helped me (see also the example code that is linked) 我遇到了类似的问题, 这个帖子中的第一个答案帮助了我(另请参阅链接的示例代码)

Th answer is basically add all modules to dependency management of the parent pom and then remove any version information from the "inter-module" dependencies in the modules. 答案基本上是将所有模块添加到父pom的依赖关系管理中,然后从模块中的“模块间”依赖关系中删除任何版本信息。

eg 例如

parent pom: 父母pom:

 <dependencyManagement>
      <dependencies>
            <dependency>
            <groupId>some_group</groupId>
            <artifactId>module_A</artifactId>
            <version>${project.version}</version>
        </dependency>
            <dependency>
            <groupId>some_group</groupId>
            <artifactId>module_B</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

module A: 模块A:

 <dependencies>
            <dependency>
            <groupId>some_group</groupId>
            <artifactId>module_B</artifactId>
        </dependency>
    </dependencies>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM