简体   繁体   English

如何使 Maven 子项目的版本与父项目不同?

[英]How to make the Maven child project to have different version than the parent?

I am very new to Maven, and I am creating a Maven parent and child project.我是 Maven 的新手,我正在创建一个 Maven 父子项目。 I want the child project to have a different version than the parent, but if I change the version, then I am getting the error Cannot resolve for some of the dependencies.我希望子项目具有与父项目不同的版本,但如果我更改版本,则会收到错误Cannot resolve某些依赖项。

How can I have a have a parent version different than the child version?我怎样才能拥有与子版本不同的父版本?

Following are the current properties I have, which are working pretty fine:以下是我拥有的当前属性,它们运行良好:

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>io.parent-test</groupId>
    <artifactId>io.parent-test</artifactId>
    <version>0.9.1-SNAPSHOT</version>
    <relativePath></relativePath>
</parent>

<artifactId>test-project-converter</artifactId>
<name>test-project</name>
<description>Test Project</description>

If I change the properties to include the different version for child then I get the error:如果我更改属性以包含子版本的不同版本,则会收到错误消息:


<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>io.parent-test</groupId>
    <artifactId>io.parent-test</artifactId>
    <version>0.9.1-SNAPSHOT</version>
    <relativePath></relativePath>
</parent>

<version>0.9.2-SNAPSHOT</version>
<artifactId>test-project-converter</artifactId>
<name>test-project</name>
<description>Test Project</description>

I have the following dependencies based on the version that is throwing the error:根据抛出错误的版本,我有以下依赖项:

<dependency>
    <groupId>io.parent-dep</groupId>
    <artifactId>parent-dev</artifactId>
    <version>${project.version}</version>
</dependency>

I tried to look into some of the responses online and made modifications to my parent project to include the properties:我试图在线查看一些回复,并对我的父项目进行了修改以包含以下属性:

<properties>
    <revision>0.9.2-SNAPSHOT</revision>
</properties>

and accordingly, change the child project to include the version <version>${revision}</version> but it's not working as expected.因此,更改子项目以包含版本<version>${revision}</version>但它没有按预期工作。

Can someone please let me know how can I create a different snapshot version for my child project while keeping the parent project same?有人可以让我知道如何在保持父项目不变的同时为我的子项目创建不同的快照版本吗?

I think because you are building wrong order of child and parent project.我认为是因为您正在构建错误的子项目和父项目顺序。 When you change the version of child project, you should first re-build child project with new version -> new jar file name (with old parent jar file if in the child project have parent dependency) then update the version of child dependency in the pom file of parent project and re-build parent project, then re-build child project again with the new parent jar file (the same version but include different child jar file).当你更改子项目的版本时,你应该首先用新版本重新构建子项目 - >新的 jar 文件名(如果子项目中有父依赖,则使用旧的父文件 jar 文件)然后更新子依赖的版本父项目的 pom 文件并重新构建父项目,然后使用新的父 jar 文件(相同版本但包含不同的子 jar 文件)再次重新构建子项目。

I was able to fix it by providing the parent version ${project.parent.version} to the dependencies coming from the parent.我能够通过向来自父级的依赖项提供父版本${project.parent.version}来修复它。

I tried this, and everything worked fine.我试过了,一切正常。

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>io.parent-test</groupId>
    <artifactId>io.parent-test</artifactId>
    <version>0.9.1-SNAPSHOT</version>
    <relativePath></relativePath>
</parent>

<version>0.9.2-SNAPSHOT</version>
<artifactId>test-project-converter</artifactId>
<name>test-project</name>
<description>Test Project</description>

<dependencies>

<dependency>
    <groupId>io.parent-dep</groupId>
    <artifactId>parent-dev</artifactId>
    <version>${project.parent.version}</version>
</dependency>

</dependencies>

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

相关问题 如何使孩子在Maven中的依赖关系与父母不同? - How to have a child have a different dependency in Maven than parent? 如何使现有的Maven父项目,新创建的Maven项目的子项目 - How to make existing maven parent project, child of newly created maven project 使Maven孩子依赖于不同版本的库 - Make maven child depend on different version of library 如何编译不同版本的Maven Web项目并在不同版本中运行 - How to compile maven web project in different version and run in different version 如何在Maven中使用来自父项的唯一子项依赖项版本 - How to use unique child dependency version from parent in maven 如何使用不同的 Java 版本和 Maven 版本在 GitLab 上运行项目? - How to run project on GitLab with different Java version and Maven version? 如何将 maven 父子项目设置为单独的项目? - How to setup maven parent and child project as separate projects? Maven:如何在父POM中引用子项目的构建目录? - Maven: How to reference the build directory of a child project in a parent POM? 如果在父项目中存在较新版本,如何排除maven依赖项 - How to exclude a maven dependency if in the parent project exists a newer version of it 如何使不同子类的实例具有其共同父类 class 的相同实例? - How do I make instances of different child classes have the same instance of their common parent class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM