I am very new to Maven, and I am creating a Maven parent and child project. 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.
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.
Can someone please let me know how can I create a different snapshot version for my child project while keeping the parent project same?
CodePudding user response:
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).
CodePudding user response:
I was able to fix it by providing the parent version ${project.parent.version}
to the dependencies coming from the parent.
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>