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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3666047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 02:56:12  来源:igfitidea点击:

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

javamaven-2

提问by mavenN00b

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). What would be the correct way of achieving this?

我认为使用聚合器可以让我对 moduleA 和 moduleB 进行“同步”发布,自动更新 moduleA 以依赖于 moduleB(1.1)。实现这一目标的正确方法是什么?

Thanks

谢谢

回答by Pascal Thivent

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. And if you don't use the Maven Release Plugin and do the release manually, you should not do that anyway.

要严格回答这个问题,这是不可能的,至少对于 Maven Release Plugin 来说是不可能的。如果您不使用 Maven 发布插件并手动进行发布,则无论如何您都不应该这样做。

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. Which is why the Maven Release Plugin enforces this.

原因:发布的构建应该是可重复的,以后从源构建它应该给出完全相同的结果。在一些已发布的 POM 中拥有一些 SNAPSHOT 依赖项完全违背了这个目标。这就是 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). What would be the correct way of achieving this?

我认为使用聚合器可以让我对 moduleA 和 moduleB 进行“同步”发布,自动更新 moduleA 以依赖于 moduleB(1.1)。实现这一目标的正确方法是什么?

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

  • moduleA should use the built-in properties to declare its dependency on B

    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>moduleB</artifactId>
      <version>${project.version}</version>
    </dependency>
    
  • moduleB 和 moduleA 不应声明任何版本,它们从父 POM 继承它

  • moduleA 应该使用内置属性来声明它对 B 的依赖

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

回答by Bertolt

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 的依赖项管理中,然后从模块中的“模块间”依赖项中删除任何版本信息。

e.g.

例如

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:

模块一:

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