2

I have the following structure with the following dependency: child1->child2.

and a parent for both which consolidates all versions in dependency management, using ${project.version}.

Folder structures:

+ parent + child1 + child2 

See poms below + complete example here.

Everything works find when child2's version is set to 1.0-SNAPSHOT.

When trying to change just child2's version to 2.0-SNAPSHOT, I get the following error:

Failure to find ...:child1:jar:2.0-SNAPSHOT 

Why is maven trying to find version child1 2.0 and not 1.0?

Parent:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>info.fastpace.issue.unknowversion</groupId> <artifactId>parent</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <modules> <module>child1</module> <module>child2</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>info.fastpace.issue.unknowversion</groupId> <artifactId>child1</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>info.fastpace.issue.unknowversion</groupId> <artifactId>child2</artifactId> <version>${project.version}</version> </dependency> </dependencies> </dependencyManagement> </project> 

Child1:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>child1</artifactId> <parent> <groupId>info.fastpace.issue.unknowversion</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> </project> 

Child2:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>child2</artifactId> <version>2.0-SNAPSHOT</version> <parent> <groupId>info.fastpace.issue.unknowversion</groupId> <artifactId>parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>info.fastpace.issue.unknowversion</groupId> <artifactId>child1</artifactId> </dependency> </dependencies> </project> 

2 Answers 2

3

It seems that replacing ${project.version} in the parent pom with hard coded 1.0-SNAPSHOT solved this.

Don't know exactly why changing to hard coded values worked, but at least works now.

Sign up to request clarification or add additional context in comments.

3 Comments

In your child2 the ${project.version} is 2.0-SNAPSHOT instead of 1.0-SNAPSHOT which I would have expected. This means for me child2 will be released in an other cycle than the rest of the project like parent and child1. This in consequence means child2 should be a separate project cause it has its own release cycle.
Imagine making it 1.0.1 instead of 2.0. Is it different now?
No there is no difference there. If not all modules including the parent have the same version a multi module build does not make sense...A multi module build is intended to have all modules / childs having the same release cycle and the same version....
0

parent.version depends on the current project, and isn't automatically replaced when generating artifacts unless you use something like flatten-maven-plugin. (Maven understands the hardcoded version and manipulates it appropriately when it is the same throughout the project, as you've discovered.) That means that using these artifacts as dependencies in any other project will not work. It also means that if a subproject is treated as the current project (such as changing to a child's subdirectory and building from there), then it dictates what parent.version is. In your case, that would directly alter the version of managed dependency for child1; this seems to be the error that you're seeing.

The parent project cannot be all of a reactor (the root POM specifying <modules>), a parent (a POM referenced by another's <parent>), and a project BOM (a POM listing the other modules of the project in <dependencyManagement>) at the same time if you want to have separate versions. You want two or even three modules for that instead of the one, and you can't use parent.version.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.