Maven项目版本继承 - 我是否必须指定父版本? [英] Maven project version inheritance - do I have to specify the parent version?

查看:2964
本文介绍了Maven项目版本继承 - 我是否必须指定父版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目:父项目:A,子项目:B

I have two projects: Parent project: A, Sub project: B

A / pom.xml:

A/pom.xml:

<groupId>com.dummy.bla</groupId>
<artifactId>parent</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>

在B / pom.xml中,我有:

And in B/pom.xml, I have:

    <parent>
        <groupId>com.dummy.bla</groupId>
        <artifactId>parent</artifactId>
        <version>0.1-SNAPSHOT</version>     
    </parent>

    <groupId>com.dummy.bla.sub</groupId>
    <artifactId>kid</artifactId>

我希望B从父母那里继承版本,所以在我的情况下我唯一需要放的地方 0.1-SNAPSHOT A / pom.xml 。但是,如果我从 B / pom.xml 下删除< version> 0.1-SNAPSHOT< / version> 父节,maven抱怨父母遗失的版本。

I want B to inherit the version from parent, so the only place in my case I need to put 0.1-SNAPSHOT is A/pom.xml. But if i remove the <version>0.1-SNAPSHOT</version> from B/pom.xml under the parent section, maven complains about the missing version for the parent.

有没有办法可以使用 $ {project.version} 或类似的东西来避免<两个poms中的code> 01.-SNAPSHOT ?

Is there a way I can just use ${project.version} or something like this to avoid having 01.-SNAPSHOT in both poms?

推荐答案

不,没有'吨。您始终必须指定父版本。幸运的是,它作为模块的版本继承,在大多数情况下是理想的。此外,这个父母的版本声明会被Maven Release Plugin自动提升,所以 - 实际上 - 只要你使用Maven Release Plugin发布版本或只是版本,你就不会有2个版本的问题。

No, there isn't. You always have to specify parent's version. Fortunately, it is inherited as the module's version what is desirable in most cases. Moreover, this parent's version declaration is bumped automatically by Maven Release Plugin, so - in fact - it's not a problem that you have version in 2 places as long as you use Maven Release Plugin for releasing or just bumping versions.

请注意,在某些情况下,此行为实际上非常正常,并提供了您可能需要的更多灵活性。有时你想使用以前父版的一些版本继承,但这不是主流的情况。

Notice that there are some cases when this behaviour is actually pretty OK and gives more flexibility you may need. Sometimes you want to use some of previous parent's version to inherit, however that's not a mainstream case.

这篇关于Maven项目版本继承 - 我是否必须指定父版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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