你能继承Maven中父POM的版本吗? [重复]

时间:2023-01-26 11:55:11

This question already has an answer here:

这个问题在这里已有答案:

I have a bunch of projects like:

我有一堆项目,如:

project1
project2
project3
........
project111

Each project compiled in jar: project-1.1.1.1.jar, .... Does it possible in parent folder add pom.xml so I can define version 1 time for all projects?

每个项目都在jar中编译:project-1.1.1.1.jar,....是否可以在父文件夹中添加pom.xml,以便为所有项目定义版本1时间?

3 个解决方案

#1


29  

If you omit <version/> it inherits from the parent. However, the <parent/> element must contain a <version/> for the parent, so the version must occur in every single POM, but only once.

如果省略 ,则它继承自父级。但是, 元素必须包含父级的 ,因此版本必须出现在每个POM中,但只能出现一次。

#2


23  

You can do this:

你可以这样做:

parent pom.xml:
<project>
  ...
  <version>${my-project-version}</version>
  ...
  <properties>
    <my-project-version>1.1.1</my-project-version>
  </properties>
</project>

child pom.xml:
<project>
  ...
  <parent>
    <relativePath>../parent/pom.xml</relativePath>
    <version>${my-project-version}</version>
  </parent>
  ...
</project>

At least, this works for me.

至少,这对我有用。

#3


5  

Using a property and referencing it works... unless you are using the release plugin to do releases in which case it removes "-SNAPSHOT" from the version and automatically replaces all instances with the real version number - which overwrites any replacement variables you've set. You may be better off just setting it in each POM and using the release plugin to tag, increment, and release your project.

使用属性并引用它有效...除非您使用发布插件来执行发布,在这种情况下,它会从版本中删除“-SNAPSHOT”并自动用实际版本号替换所有实例 - 这会覆盖任何替换变量'设置。您可能最好只在每个POM中设置它并使用release插件来标记,增加和释放项目。

#1


29  

If you omit <version/> it inherits from the parent. However, the <parent/> element must contain a <version/> for the parent, so the version must occur in every single POM, but only once.

如果省略 ,则它继承自父级。但是, 元素必须包含父级的 ,因此版本必须出现在每个POM中,但只能出现一次。

#2


23  

You can do this:

你可以这样做:

parent pom.xml:
<project>
  ...
  <version>${my-project-version}</version>
  ...
  <properties>
    <my-project-version>1.1.1</my-project-version>
  </properties>
</project>

child pom.xml:
<project>
  ...
  <parent>
    <relativePath>../parent/pom.xml</relativePath>
    <version>${my-project-version}</version>
  </parent>
  ...
</project>

At least, this works for me.

至少,这对我有用。

#3


5  

Using a property and referencing it works... unless you are using the release plugin to do releases in which case it removes "-SNAPSHOT" from the version and automatically replaces all instances with the real version number - which overwrites any replacement variables you've set. You may be better off just setting it in each POM and using the release plugin to tag, increment, and release your project.

使用属性并引用它有效...除非您使用发布插件来执行发布,在这种情况下,它会从版本中删除“-SNAPSHOT”并自动用实际版本号替换所有实例 - 这会覆盖任何替换变量'设置。您可能最好只在每个POM中设置它并使用release插件来标记,增加和释放项目。